how to Leverage browser caching in django

最后都变了- 提交于 2020-01-23 06:57:15

问题


I made a small site in Django but while checking the site performance with Google pagespeed I get the recommendation as Leverage browser caching but i cant find a way to achieve it in django


回答1:


For views, you use the cache_control decorator.


For static content, do this in your web server configuration. If you're using nginx, here's what you need to add to your Nginx site configuration:

location ~* \.(css|js|gif|jpe?g|png)$ {
  expires 168h;
  add_header Pragma public;
  add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}

You might want to customize this a bit (e.g. match your STATIC_PATH instead of extensions, or use different expires headers).



来源:https://stackoverflow.com/questions/20147587/how-to-leverage-browser-caching-in-django

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