Last active
May 14, 2023 13:46
-
-
Save lukecav/ed29bd779ccb2f8a46fc8b30ed48c141 to your computer and use it in GitHub Desktop.
Browser caching rules for NGNIX and expire headers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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"; | |
} |
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
http://nginx.org/en/docs/http/ngx_http_headers_module.html