问题
Currently have a project deployed on Heroku with static files loaded from S3. I'm using boto/django-storage to manage my S3 content, but if I call the same view or load the same page repeatedly, all the images/static content load twice and is not cached.
I've placed
AWS_HEADERS = {
'Cache-Control': 'max-age=2592000',
}
in my settings.py
, but the reason seems the same exact images (refreshed + loaded twice) have different signatures in their URL? I've tried multiples headers, but the browser doesn't seem want to cache it and instead loads them all everytime.
回答1:
try setting AWS_QUERYSTRING_AUTH = False
. Then the URL generated will always be the same (public) URL. The default-ACL in S3BotoStorage
is public-read
, which shouldn't be changed then.
Two things not to forget:
- perhaps you want to add
public, max-age=XXX
, so public proxies also can cache your content? - When you want the browser to cache that long, you should keep in mind that the filenames have to change when you change the content. One solution would be to
S3BotoStorage
combined with the Django-CachedStaticFilesStorage
(see here, but I use it without the seperate cache-backend)
来源:https://stackoverflow.com/questions/19104165/heroku-s3-django-static-files-not-cached