How to use browser caching in django

I made a small site in Django, but checking the site’s performance using Google pages, I get a recommendation on how to cache Leverage browsers, but I can’t find a way to achieve it in django

+4
source share
1 answer

For views, you use a decorator cache_control.


For static content, do this in your web server configuration. If you are using nginx, here is 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 tweak it a bit (for example, match yours STATIC_PATHinstead of extensions, or use different expiration headers).

+7

All Articles