Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid precompiled assets being served in development mode?

People also ask

How do I Precompile assets in Heroku?

To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.

What does rake assets Precompile do?

rake assets:precompile. We use rake assets:precompile to precompile our assets before pushing code to production. This command precompiles assets and places them under the public/assets directory in our Rails application.


In config/environments/development.rb set:

config.assets.prefix = "/assets_dev"

so that in development mode Rails will look there (but it will not find anything, as you will not compile assets in development (this is indeed what you are trying to do -- not compile assets)).

When precompiling for production, use

RAILS_ENV=production rake assets:precompile

so it compiles into the default assets folder, public/assets.


It sounds like you are precompiling locally. Because the files exist in the expected location they are being served by your dev server, and the requests are not going to Sprockets.

The only way to stop this is delete the compiled files.

Normally you do not need to compile locally. It is expected that in almost all cases the precompile task will be run during deployment of the app. There is a Capistrano recipe for this on the asset pipeline guide page.

If you do need to have those files locally committed to your repo you could use a branch to avoid the problem. Reserve your master branch for production code, and make a second branch for dev. Only compile and commit assets on master. When you switch to dev, they will be gone. Merge dev into master as required.

Edit: Make sure you force your browser to update (control + F5) or you may find the old assets used from the browser cache!


in config/environments/development.rb set:

config.serve_static_assets = false

and no files from /public will be served


I tried this and it worked. rake assets:precompile RAILS_ENV=production

I observed that the new version of assets pipeline does this when you run rake assets:precompile does rake assets:precompile:all