Safely recompiling all assets on Rails 4 deployment?

1.6k Views Asked by At

Right now I have occasional issues with the Rails 4 asset pipeline that requires removing all assets and then recreating the assets.

During deployment, after pulling the latest from git, I refresh the assets by running, rake assets:clobber and then rake assets:precompile on my server. The problem is that during the time the assets are removed, the page gets served, not surprisingly, with no assets.

Is there anyway to force Rails to recompile all assets without having to run assets:clobber?

2

There are 2 best solutions below

7
On

Here is what I usually do, when precompiling the assets.

// At a terminal, remove all assets from the file system
$ rm -rf public/assets  
// Precompile the assets
$ rake assets:precompile

Always worked for me.

3
On

First run rake assets:precompile then run rake assets:clean. That will only remove old assets. https://github.com/rails/sprockets-rails/blob/master/README.md#rake-task