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 host.

server {
    root /path/to/static/;
    location ~* ^/(\w+)/(\w+)_[\d-]+\.(css|js) {
        alias /path/to/static/$1/$2.$3;
        expires max;
Published on Feb. 17, 2013 by Nicolas and tagged Cache, nginx. You can follow the discussion with the comment feed for this post. Feeling generous? Donate!


Start a new thread

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