3rd Party Script Caching in Rails 3.1 3rd Party Script Caching in Rails 3.1 nginx nginx

3rd Party Script Caching in Rails 3.1


If you have a script with a name that is part of your public interface then you need to start versioning this script explicitly, and keeping old versions around for older clients.

e.g. /assets/script.1.0.js, /assets/script.1.1.js etc

The key part is that you need to be keeping the old ones around, and the code doesn't change without the name changing explicitly. The Rails asset pipeline can't do this for you, since there's usually only the very latest version of the script kept current.

As with all public interfaces, you will need to spend more time on managing this process than you would for an internal-only script.


I recommend using an ETag.Add an ETag header to your responsehttp://en.wikipedia.org/wiki/HTTP_ETag

Set the ETag header to a different, unique string for each version of your script.This will make sure browsers get a new version of the script whenever you deploy a new version .


nginx is able to generate etags in the latest version: http://nginx.org/en/docs/http/ngx_http_core_module.html#etag

I've also seen the configuration below here: https://serverfault.com/questions/426260/nginx-cache-control

location /static {  alias /opt/static/blog/;  access_log off;  etags on;  etag_hash on;  etag_hash_method md5;  expires     1d;  add_header Pragma "public";  add_header Cache-Control  "public, must-revalidate, proxy-revalidate";}