Skip to content

Instantly share code, notes, and snippets.

@solid-pixel
Last active July 29, 2020 20:44
Show Gist options
  • Save solid-pixel/f10522157c5717d25fcd4530fb22d8e7 to your computer and use it in GitHub Desktop.
Save solid-pixel/f10522157c5717d25fcd4530fb22d8e7 to your computer and use it in GitHub Desktop.
Leverage Browser Caching with NGINX
  • Add this code to your website's NGINX configuration, in /var/www/yourwebsite/conf/nginx/
  • "nginx -t" and "service nginx reload" to apply the modification.
location ~* \.(?:css|js|txt)$ {
expires 1y;
sendfile on;
tcp_nopush on;
tcp_nodelay off;
add_header Cache-Control "public";
}
#Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
location ~* \.(?:ttf|ttc|otf|eot|woff|woff2)$ {
expires 1M;
sendfile on;
tcp_nopush on;
tcp_nodelay off;
add_header Cache-Control "public";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment