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
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With