Heroku + S3 + Django: Static Files not Cached

☆樱花仙子☆ 提交于 2019-12-11 07:35:43

问题


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 S3BotoStorageis 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!