Cache busting with nginx

Here's a little snippet for cache busting without abusing a query string which can lead to caching problems.

The example below will rewrite paths like /css/foo_20130401-5.css to /path/to/static/css/foo.css on the static.example.com host.

Raw
server {
    server_name static.example.com;
    root /path/to/static/;
    location ~* ^/(\w+)/(\w+)_[\d-]+\.(css|js) {
        alias /path/to/static/$1/$2.$3;
        expires max;
    }   
}

0 comments

Reply

Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.
DjangoPythonBitcoinTuxDebianHTML5 badgeSaltStackUpset confused bugMoneyHackerUpset confused bugX.OrggitFirefoxWindowMakerBashIs it worth the time?i3 window managerWagtailContainerIrssiNginxSilenceUse a maskWorldInternet securityPianoFontGnuPGThunderbirdJenkinshome-assistant-logo