Nuanda / smogmapper

Smog Mapper
http://smogmapper.smogathon.pl/
1 stars 0 forks source link

Assets - make sure caching works as expected #13

Closed Nuanda closed 8 years ago

Nuanda commented 8 years ago

Currently I think it does not work. For instance, when reloading the page, the app.js and app.css files are downloaded afresh (200 KB of data) instead of getting the 304 response. Same for the icons font file.

mkasztelnik commented 8 years ago

How it is configured on production? It is the best to configure something like this in nginx:

location ~* ^/assets/ {                                                                                                        
  # Per RFC2616 - 1 year maximum expiry                                                                                        
  expires 1y;                                                                                                                  
  add_header Cache-Control public;                                                                                             

  # Some browsers still send conditional-GET requests if there's a                                                             
  # Last-Modified header or an ETag header even if they haven't                                                                
  # reached the expiry date sent in the Expires header.                                                                        
  add_header Last-Modified "";                                                                                                 
  add_header ETag "";                                                                                                          
  break;                                                                                                                       
}  
Nuanda commented 8 years ago

It's exactly like that, and also gzip is turned on.

Nuanda commented 8 years ago

Hmm, it appears the Last-Modified header confuses the process. When commented out, the 304 response is returned and the browser takes its internal,. cached version. I found it thanks to that minimal setting tutorial: http://vladigleba.com/blog/2014/03/27/deploying-rails-apps-part-4-configuring-nginx/

i don't think resetting Last-Modified to an empty string is important, as long as rails renames the assets after recompile, right?

Nuanda commented 8 years ago

Tested on Chromium, FF, Opera (all Linux) and Chrome (And 5.1.1 Nexus 7) and removing Last-Modified overwrite turns caching on. Yay, everybody rejoice.

mkasztelnik commented 8 years ago

This also works for plgapp, thx for hint :+1:

Nuanda commented 8 years ago

IE test, anyone? ;)

Nuanda commented 8 years ago

Tested in IE11.