This post is part of a series of 31 Rails 4 articles being released each day in December 2012.
When the asset pipeline was introduced in Rails 3.1, it changed how we fundamentally worked with assets. It provided structure and practices on how to include assets in our projects. No longer did we just dump everything into the
There were some issues that plagued the feature. For one, improvements to the
sprockets gem were never brought over to Rails. Action Pack had a hard dependency to a specific version of sprockets, which as of Rails 3.2.9 is version 2.2.1. Another issue that annoyed some developers was the excessive logging that occurred when assets were requested.
These issues have since been resolved in Rails 4. One of the fundamental changes to the framework, is its move to be modular by extracting certain features to gems. As of Rails 4, the asset pipeline has been extracted to a gem, named
sprocket-rails. This change will allow the asset pipeline to improve independently from the core framework. This is similar to how Rails handles inclusion of asset pipeline complimentary plugins,
The configuration option
config.assets.logger has been removed. Sprockets will no longer pollute your logs when assets are compiled. Nevertheless, Action Pack will continue to log when assets are requested from your server if they are not precompiled.
The biggest thing developers will notice when they upgrade to Rails 4 will be the speed at which assets precompile. In an excellent blog post by Guillermo Iguaran, he outlined the speed difference with
sprocket-rails. Using the new
sprocket-rails gem, he was able to precompile assets that used to take 9.339 seconds and compile them in only 1.752 seconds. That's a 81.24% improvement!