Invalidate cache for static files?

Maxim Dounin mdounin at mdounin.ru
Mon Jul 21 18:10:34 MSD 2008


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.

Alternatively you may force nginx to disable cache for specific 
urls via expires directive, see 
http://wiki.codemongers.com/NginxHttpHeadersModule#expires.  But 
this is probably not what you want since this will:

     a) Disable cache for all requests, not only when something 
get's changed on server.
     b) Sometimes ignored by browsers.

Maxim Dounin





More information about the nginx mailing list