Cache Busting and Include Files for Nginx
- by Vince Kronlein
In Apache you can use the following to cache bust css and js files and server them as a single file with Apache's Include mod:
<FilesMatch "\.combined\.js$">
Options +Includes
AddOutputFilterByType INCLUDES application/javascript application/json
SetOutputFilter INCLUDES
</FilesMatch>
<FilesMatch "\.combined\.css$">
Options +Includes
AddOutputFilterByType INCLUDES text/css
SetOutputFilter INCLUDES
</FilesMatch>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L]
</IfModule>
I know this is possible with nginx but I can't seem to get the syntax correct.
-- EDIT --
Adding some code
The only piece I have thus far is:
location ~* (.+)\.(?:\d+)\.(js|css)$ {
ssi on;
try_files $uri $1.$2;
}
What I'm looking for is to be able to combine all js and css files into single files using the combined keyword with a number for cache busting:
style.combined.100.css
javascript.combined.100.js