Rails 3.1 & Sprockets and compiled JS files

So, just try Rails 3.1-rc1 with the Sprockets pipeline:

I ran rake assets:precompile

and I get the directory / public / assets, and the application.js file is an MD5 hash:

 application-266b6b0b4fbd28fc01145d90a4158b2f.js 

But the problem is this:

When I update JS and run rake assets:precompile , I get more JS files and it does not delete the old ones.

I have no doubt how this works - the browser only picks up the first one, and I have to manually delete the old ones. Which is not like how it should work.

Just a side handle: It seems I need to run rake assets:precompile every time I change something. This is painful.

(I suppose there should be some docs about how this all works).

Thanks.

+4
source share
1 answer

Js file name: <file name> - <hash> .js.

This made it so that when you deploy the new version of the application to the production server, your visitors will also have to upload a new js file. The hash ensures that they will not mix the new application and the old cached js, which can break the entire application, given the dynamic nature of the Internet these days.

In most deployment scenarios, you will have your application in a new directory on the server, and you will not have old compiled js files.

+4
source

All Articles