# Best way to burst static file cache

**URL:** <https://www.ruby-forum.com/t/best-way-to-burst-static-file-cache/212224>\
**Category:** NGINX\
**Created:** [September 26, 2011, 12:11pm UTC](https://www.ruby-forum.com/t/best-way-to-burst-static-file-cache/212224 "2011-09-26T12:11:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [September 26, 2011, 12:11pm UTC](https://www.ruby-forum.com/t/best-way-to-burst-static-file-cache/212224/1 "2011-09-26T12:11:57Z")

</div>

Hi

Loving nginx, thanks Igor!

I’m caching static files in a very traditional way, I hope:  
location ~\* .(js|css|png|jpg|jpeg|gif|ico)$ {  
#expires max;  
expires 30m;  
access\_log off;  
log\_not\_found on;  
}

I would like to have longer caching. Sometimes there is a fast turn  
around on live sites and clients have an issue bursting the cache. These  
tend to be Windows based clients. No matter what they or I do, they  
continue to retrieve cached versions of css and pngs.

Is there a better configuration, or anything that I am not doing at my  
end to ensure they get served the fresh files?

Posted at Nginx Forum:

> **[Best way to burst static file cache](https://forum.nginx.org/read.php?2,215835,215835#msg-215835)**
>
> Hi Loving nginx, thanks Igor! I'm caching static files in a very traditional way, I hope: location ~\* \\.(js|css|png|jpg|jpeg|gif|ico)$ { #expires max; expires 30m; access\_log off; log\_not\_found on

---

<div class="post-metadata">

**Author:** ![tcbarrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e0b2c6/32.png) [@tcbarrett](https://www.ruby-forum.com/u/tcbarrett)\
**Post date:** [September 29, 2011, 5:07pm UTC](https://www.ruby-forum.com/t/best-way-to-burst-static-file-cache/212224/2 "2011-09-29T17:07:02Z")

</div>

Nobody has any ideas?

Posted at Nginx Forum:

> **[Re: Best way to burst static file cache](https://forum.nginx.org/read.php?2,215835,216034#msg-216034)**
>
> Hi Loving nginx, thanks Igor! I'm caching static files in a very traditional way, I hope: location ~\* \\.(js|css|png|jpg|jpeg|gif|ico)$ { #expires max; expires 30m; access\_log off; log\_not\_found on

---

<div class="post-metadata">

**Author:** ![tcbarrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e0b2c6/32.png) [@tcbarrett](https://www.ruby-forum.com/u/tcbarrett)\
**Post date:** [September 30, 2011, 1:09am UTC](https://www.ruby-forum.com/t/best-way-to-burst-static-file-cache/212224/3 "2011-09-30T01:09:47Z")

</div>

Well, if you set cache to expire 30 years from now the browser should  
honor that, that is if no Last-Modified is set.

Posted at Nginx Forum:

> **[Re: Best way to burst static file cache](https://forum.nginx.org/read.php?2,215835,216076#msg-216076)**
>
> Hi Loving nginx, thanks Igor! I'm caching static files in a very traditional way, I hope: location ~\* \\.(js|css|png|jpg|jpeg|gif|ico)$ { #expires max; expires 30m; access\_log off; log\_not\_found on

---

<div class="post-metadata">

**Author:** ![tcbarrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e0b2c6/32.png) [@tcbarrett](https://www.ruby-forum.com/u/tcbarrett)\
**Post date:** [October 2, 2011, 2:34pm UTC](https://www.ruby-forum.com/t/best-way-to-burst-static-file-cache/212224/4 "2011-10-02T14:34:39Z")

</div>

## kaspars Wrote:

> Well, if you set cache to expire 30 years from now  
> the browser should honor that, that is if no  
> Last-Modified is set.

I have it set to 30m (30 minutes, right?). If I update, for example,  
some css files and then a do a hard refresh on a) a Mac then I get the  
new css or b) Windows 7 then I keep getting the cached css files.

Is there any technique to burst this caching. It might not be a ‘pure  
nginx’ solution, but anything that could be supported by an nginx config  
setting?

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,215835,216179#msg-216179](http://forum.nginx.org/read.php?2,215835,216179#msg-216179)

---

<div class="post-metadata">

**Author:** ![tcbarrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e0b2c6/32.png) [@tcbarrett](https://www.ruby-forum.com/u/tcbarrett)\
**Post date:** [October 2, 2011, 3:16pm UTC](https://www.ruby-forum.com/t/best-way-to-burst-static-file-cache/212224/5 "2011-10-02T15:16:33Z")

</div>

On 02/10/2011 13:34, tcbarrett wrote:

> nginx’ solution, but anything that could be supported by an nginx config  
> setting?

What everyone else does is set the URLs to be unique and then change the  
url when the asset is updated. eg a simple example which rails uses and  
arguably isn’t perfect would be:

```
/assets/blah.jpg?12333234

```

The random string after the ? could be generated in various ways, eg  
incrementing counter or it could be the epoch time of the file mtime (ie  
age in seconds)

Now you can set expire time to 30 years and when the asset is updated  
you simply arrange for the url to be updated in the html and a “new”  
image is pulled down

Implementation left to the reader as an exercise…

Ed W
