Sprockets max-age header on heroku

383 views Asked by At

My application.js file name looks like application-b600352536291bc180983d43e6a2407f.js. So it has the md5 cache buster in its name. I have set the max-age option for static assets to 1 hour config.static_cache_control = "public, max-age=3600". But i am observing that the browser is not respecting the max-age header and always revalidates from the server and does a round trip for a 304 Not Modified. How can i save the round trip?

Request Headers

Request URL:https://blah.com/assets/application-b600352536291bc180983d43e6a2407f.js  
Request Method:GET  
Status Code:304 Not Modified  
Request Headersview source  
Accept:*/*  
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3  
Accept-Encoding:gzip,deflate,sdch  
Accept-Language:en-US,en;q=0.8  
Cache-Control:max-age=0  
Connection:keep-alive  
If-Modified-Since:Sun, 12 Feb 2012 07:36:16 GMT    

Response Headers

Cache-Control:public, max-age=3600
Connection:keep-alive
Date:Sun, 12 Feb 2012 18:27:48 GMT
Last-Modified:Sun, 12 Feb 2012 07:36:16 GMT
Server:nginx
Vary:Accept-Encoding
Via:1.1 varnish
X-Varnish:499878183
1

There are 1 answers

0
Ross Allen On

Are you pressing Command + R or Ctrl + R? The browser refresh button intentionally re-checks the freshness of its assets. It assumes you're hitting refresh because something didn't function properly on the page.

If you want to test the headers, visit the page once and then focus the location bar and press Enter to visit it a second time. The assets should come from the cache.