Invalidate cache for static files?

Tit Petric black at
Mon Jul 21 19:37:04 MSD 2008

Yes, that's the idea.

You replace a part of the url with a version string, this can be a 
folder, or it can be the filename itself.

Moving them is a lazy man's sollution to a rewrite rule, which handles 
this for you, so you don't have to copy files around on each revision / 

This is a paradigm that can be applied to any web server with support 
for rewriting rules (apache, lighttpd, nginx,...).

P.s. off-topic, will you publish your slides on optimisation, from the 
php 08 conference? I missed your talk, and I would really like to see 
what you had to say, since the videolectures aren't uploaded yet.

BR, Tit

Denis Arh wrote:
> Would it help moving them into a different folder instead of appending 
> query string?
> Sent from my iPhone
> On 21.7.2008, at 16:55, Tit Petric <black at> wrote:
>> Maxim Dounin wrote:
>>> Hello!
>>> On Mon, Jul 21, 2008 at 01:57:06PM +0100, Phillip B Oldham wrote:
>>>> What would be the simplest way to invalidate browser cache of 
>>>> static  files served by nginx?
>>>> For instance, we have a website which is in active development. We 
>>>> get a  reasonable amount of traffic, but we often get complaints 
>>>> when we update  the live files because some browsers are working 
>>>> with a mix of fresh  (live) and stale (cached) js/css files. We'd 
>>>> like to inform/force  browsers that the file is new and should be 
>>>> updated.
>>> Just use normal web development practices, e.g. add "?v=<version>"
>>> to js/css urls.  Nothing special, nginx is just web server.
>> I've tried this before, it is problematic since cache doesn't behave 
>> correctly and in some cases browsers or even caching proxies in front 
>> of backend servers never cache the resource, because they percieve 
>> the link as dynamic.
>> Having unique urls, like I suggested in the previous email, solves 
>> theese problems. Also, you can then set the Expires & Cache-control 
>> headers for static content far in the future and encourage browser 
>> caching, since you have an effective method of always reloading them 
>> without fail. Caches and browsers will keep such objects, while the 
>> suggested sollution with the "?v=version" will not be cached on many 
>> of them, since they percieve the url as dynamic and always try a 
>> reload, ignoring possible Expires & Cache-control headers.
>> For a small setup, where you don't care about resources, your 
>> sollution is mostly fine, but is problematic in the real world with 
>> tens of thousands of users.
>> BR

More information about the nginx mailing list