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.

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;
    }   
}
Published on Feb. 17, 2013 at 3:42 p.m. by Nicolas and tagged nginx, Cache. You can follow the discussion with the comment feed for this post. Feeling generous? Donate!

0 comments

Start a new thread

Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.