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.
As part of the upcoming 0.70.0 release we’re returning to an earlier approach
of bundling themes as their own Rails 3.1 engine. This is primarily designed to
make installing and managing themes fall inline with extensions.
We’ve created two front-end themes to help show this new approach in action:
- Spree Blue – Recreates the original “blue” front-end theme of 0.60.x as a stand alone theme.
- Rails Dog Radio – This recreates some of the aspects of the Rails Dog Radio demo application for a default Spree application.
Both themes can be installed by just adding a reference to the git repository to your Gemfile, ie:
gem ‘spree_blue_theme’, :git => ‘git://github.com/spree/spree_blue_theme.git’
NOTE: The repo’s for both themes have be recently moved and renamed,
be sure to use the new repos locations linked above.
Edge basic theme
The current edge version of Spree includes quite a substantial
simplication of the front-end views and styles aimed at providing a simpler base to start
building themes on top of. Some early adopters have mistaken these
changes as issues with the new asset pipeline, because it no longer
sports the classic “blue” look.
To restore the original 0.60.x look, please install the Spree Blue
Theme as mentioned above.
You can learn more about themes in the Extensions &
As the release of our next major version (0.70.0) draws ever nearer we
feel its time to merge the rails3-1 development branch into master, and
start helping you get ready for some of the changes you’ll need to make as part of the upgrade.
While most of the changes required are standard when upgrading any Rails
application to Rails 3.1, we’ve set out some guidelines and suggestions relating to the asset pipeline to help standardize how Spree applications and extensions make use of this new feature.
While edge has contained some new theming features (Deface) for a while now the rails3-1 branch really ties this together with the Rails asset pipeline to provide an amazingly powerful and flexiable theming eco-system.
Some lite reading
There’s a lot of changes and improvements to cover so we’ve created a lot of documentation to help explain all these new features, and we strongly recommend you read through them before diving in:
- 0.70.0 Release Notes – While 0.70.0 isn’t actually released yet, these notes are available now and provide detailed Upgrade Instructions for upgrading 0.60.x applications to 0.70.0.
- Customization Overview – This edge guide covers all customization options now available with
Spree, and explains how to organize (or bundle) those customizations.
- View Customization – Explains how to use Deface and template replacements to alter the appearance of a Spree application.
- Asset Customization – Covers Spree’s use of the asset pipeline and how you can leverage
All of these documents are works in progress and will be amended as we get closer to release.
Not ready for Rails 3.1 yet?
For those of you who have been developing on Spree edge and don’t want
to undertake the upgrade to Rails 3.1 yet, please update your Gemfile to
use the rails-3-0 branch, which is just a direct branch of the master
before rails-3-1 was merged down.
While this branch probably won’t get any direct development it’s the
safest version to use until you’re ready to upgrade to 0.70.0.
We’re always glad to help as many people as possible contribute to Spree
and there’s still plenty of
wating to be resolved, so now’s a great time to start contributing!