2014-05-13 27 views
1

我使用Django Compressor進行脫機壓縮並將壓縮的靜態文件存儲在Amazon S3上。我的問題是manifest.json引用指定http://作爲協議的緩存文件:Django Compressor的manifest.json中的協議相關url

<link rel=\"stylesheet\" 
href=\"http://stage-media.dropspot-app.com.s3.amazonaws.com/static/CACHE/css/abffb776bf3e.css\" 
type=\"text/css\" media=\"all\" /><link rel=\"stylesheet\" 
href=\"http://stage-media.dropspot-app.com.s3.amazonaws.com/static/CACHE/css/9533603cdbaa.css\"  
type=\"text/css\" media=\"screen\" 
/> 

網頁時通過HTTPS訪問。這會導致無法加載緩存文件: The page at 'https://example.com' was loaded over HTTPS, but ran insecure content from 'http://example.com.s3.amazonaws.com/static/CACHE/css/abffb776bf3e.css': this content should also be loaded over HTTPS.

的解決辦法是有manifest.json引用緩存的文件,但不會在url中包含http:,但尚未找到以這種方式生成它的方法。

有沒有辦法用協議相關的URL生成manifest.json

回答

1

這是一個古老的問題,但我花了很多時間試圖解決它最近。
這confiuration將使django-compress在兩個清單和壓縮標籤產生相對協議網址:

AWS_S3_SECURE_URLS = False 
AWS_QUERYSTRING_AUTH = False 
AWS_S3_URL_PROTOCOL = '' 
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME 

STATIC_URL = "//%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, STATICFILES_LOCATION) 

AWS_S3_CUSTOM_DOMAIN爲向後兼容性重要的,如果省略此將不工作。