Skip to content

Instantly share code, notes, and snippets.

@lukecav
Last active May 14, 2023 13:46
  • Star 6 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lukecav/ed29bd779ccb2f8a46fc8b30ed48c141 to your computer and use it in GitHub Desktop.
Browser caching rules for NGNIX and expire headers.
# Browser caching of static assets.
location ~* \.(jpg|jpeg|png|gif|ico|css|js|pdf)$ {
expires 7d;
add_header Cache-Control "public, no-transform";
}
# Media: images, icons, video, audio send expires headers
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
# Web fonts send expires headers
location ~* \.(?:eot|otf|ttf|woff|woff2)$ {
expires 3M;
access_log off;
add_header Cache-Control "public";
}
# CSS and Javascript send expires headers.
location ~* \.(?:css|js)$ {
expires 1y;
access_log off;
add_header Cache-Control "public";
}
# HTML send expires headers.
location ~* \.(html)$ {
expires 7d;
access_log off;
add_header Cache-Control "public";
}
@lukecav
Copy link
Author

lukecav commented Aug 1, 2017

@AdamZaczek
Copy link

I've been looking for similar settings, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment