ndbroadbent / turbo-sprockets-rails3

Speeds up your Rails 3 assets:precompile by only recompiling changed files, and only compiling once to generate all assets
MIT License
976 stars 78 forks source link

Upgrading Sprockets/Compatibility #102

Open mcorner opened 9 years ago

mcorner commented 9 years ago

We ran into an interesting issue in production. With the exact same set of source app/assets, turbo sprockets on two machines produced two different files in public/assets, and thus different hashes and file names. So an html file on one of our machines referred to a js file that didn't exist on another. Because of our load balancer we were getting badly rendered pages at random.

Interestingly they are only, very, very subtly different. In 0.3.10 jquery becomes J, like "J.type(t)" and in 0.3.14 it becomes K, like "K.type(t)". I don't think I see any other differences.

We traced this back to an upgrade and rollback of a release on some of the machines (others were left alone). The upgrade went from turbo sprockets 0.3.10 -> 0.3.14. When that happened on the release machines we got an incompatible set of files. But when we downgraded it didn't regenerate the public/assets (this is kind of turbo sprockets job). So with the same release on two machines we had incompatible assets between them.

I think I have traced this to one commit: https://github.com/ndbroadbent/turbo-sprockets-rails3/commit/2979f05cb1700091736e8a485856cc3c56f1efe3

Before that release I believe Sprockets::SafetyColons is in the set of processors, but after that it isn't. So I am guessing that is the incompatibility.

So....
1) Are different versions of turbosprockets guaranteed to produce the same assets with the same files? I am guessing not :) 2) What is the best practice in upgrading turbosprockets? Always clean after upgrading? 3) If one downgrades one should also clean? 4) You can't really have multiple versions of turbosprockets on one set of load balanced machines can you?

charlietran commented 9 years ago

@mcorner thanks for filing this, we've noticed the same thing! were you ever able to find a satisfactory solution? thinking of rolling back our turbo sprockets gem to 0.3.10.

mcorner commented 9 years ago

Not really. Our plan is to rsync the assets to a central location and then use a CDN in front of that. (In our case it would be something like cloudfront->s3) This gets around any out of sync problems between machines. That would solve the problem in a more general and reliable fashion.