Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to Leverage browser caching in django

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

like image 949
Sar009 Avatar asked Nov 22 '13 14:11

Sar009


1 Answers

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).

like image 200
Thomas Orozco Avatar answered Sep 21 '22 04:09

Thomas Orozco