问题
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