Comments on Make Browsers Cache Static Files On nginx
This tutorial explains how you can configure nginx to set the Expires HTTP header and the max-age directive of the Cache-Control HTTP header of static files (such as images, CSS and Javascript files) to a date in the future so that these files will be cached by your visitors' browsers. This saves bandwidth and makes your web site appear faster (if a user visits your site for a second time, static files will be fetched from the browser cache).
5 Comment(s)
Comments
I spent about two weeks to config nginx according to google-recommendation about leverage browser caching. Only on this page I found a useful solution - on a lot of other sites I saw only htaccess modifications that couldn't help me. Thank you
Hi there
I followed your suggestion but in gtmetrix it still shows that it needs to be addressed. I added this
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 365d;}
to the end of the configurationThanks
Maco
I guess the block needs to be added inside the server Tag not at the end
Can be setting max-age in Nginx on shared hosting?
Thank you.
When your hoster is using a control panel like ISPConfig that allows you to set custom Nginx rules, then yes. Otherwise, no.