August 2017
Intermediate to advanced
278 pages
8h 53m
English
For sites where the static media files (such as CSS, JS, and images) have a version number in their filename, we can easily cache the files with a long expiry without causing any issues. This means that, unless a user clears their cache, they will have a copy of this file to speed up page reloads. To set the caching, we will use a location block directive (within your main server block directive) to add the additional headers. Here's the code required:
location /static {
expires 365d;
add_header Pragma public;
add_header Cache-Control "public";}
To see the headers, we can use Chrome Developer Tools (DevTools) or a command-line tool such as cURL. If you want to run this via cURL, here's how to do it:
curl --head http://headermod.nginxcookbook.com/static/image.png ...
Read now
Unlock full access