Skip to content

Instantly share code, notes, and snippets.

@danielpotthast
Created May 26, 2018 05:08
Show Gist options
  • Save danielpotthast/e66fa8e20fd2f0180a52ca0cdb2d0f7f to your computer and use it in GitHub Desktop.
Save danielpotthast/e66fa8e20fd2f0180a52ca0cdb2d0f7f to your computer and use it in GitHub Desktop.
NGINX – Snippet: Caching
# Fonts
if ( $uri ~* ^.+?\.(?:eot|svg|svgz|ttf|woff|woff2)$ ) {
expires 30d;
access_log off;
add_header Cache-Control "public";
add_header Access-Control-Allow-Origin *;
}
# Feed
if ( $uri ~* ^.+?\.(?:rss|atom)$ ) {
expires 1h;
access_log off;
add_header Cache-Control "public";
}
# Media: images, icons, video, audio
if ( $uri ~* ^.+?\.(?:jpg|jpeg|gif|png|ico|cur|gz|mp4|ogg|ogv|webm)$ ) {
expires 30d;
access_log off;
add_header Cache-Control "public";
}
# CSS and Javascript
if ( $uri ~* ^.+?\.(?:css|js)$ ) {
expires 30d;
access_log off;
add_header Cache-Control "public";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment