This can be especially noticeable in development mode when using a single process application server like Webrick. We’ve recently update the edge version of Spree to include a small tweak to the standard pre-compiling rake task that allows pre-compiling of assets in development mode.
Pre-compiling in production
Rails supports pre-compiling of assets which is intended to offload the overhead of generating and serving assets from the application server in production environments.
Pre-compiling is not required for the asset pipeline to function
correctly in production, if you choose to not pre-compile Rails will generate each asset only once and serve each subsequent request using Rack::Cache.
Rack::Cache is generally sufficient for lower traffic sites, but
pre-compiling will provide some additional speed increases by allowing
the web server to serve all assets, including gzipped versions of
To pre-compile assets for production you would normally execute the
following rake task (on the production server).
$ bundle exec rake assets:precompile
This would write all the assets to the public/assets directory while including an MD5 fingerprint in the filename for added caching benefits.
Pre-compiling for development
Spree alters the behaviour of the precompile rake task so when you execute it passing the RAILS_ENV environmental variable, as follows:
$ bundle exec rake assets:precompile RAILS_ENV=development
It will still output the assets to public/assets but it will not include the MD5 fingerprint in the filename, hence the files will be served in development directly by the web server (and not processed by Rails).
WARNING: Using the precompile rake task in development will prevent
any changes to asset files from being automatically loaded in when you
reload the page. You must re-run the precompile task for changes to
Rail’s also provides the following rake task that will delete the entire public/assets directory, this can be helpful to clear out development assets before committing.
It might also be worthwhile to include the public/assets directory in your .gitignore file.