We use asset helpers such as
perform_caching configuration option is set to
Rails applications default to having caching disabled during development, and enabled in production. We can change this in
config/environments/development.rb to test out caching during development.
config.action_controller.perform_caching = true
We enable asset caching in our applications using the
When caching is disabled, Rails will generate the normal references to these resources.
As you can see in the above example, we’re going to store our asset cache in subdirectories named
<%= stylesheet_link_tag "typography", "layout", "color", :cache => "cache/all" %>
Rails comes with some useful built-in tasks for clearing out temporary files under the
tmp: rake namespace. Rails does not come with a built-in task for clearing out the asset cache. We’ll add this ourselves by adding a new rake task named rake
tmp:assets:clear. Create a new file in your Rails application named at
lib/tasks/tmp.rake, and add the following code.
tmp:assets:clear task we added removes all files from both the
stylesheets/cache/ directories. Let’s give it a whirl:
$> rake tmp:assets:clear
For additional performance increases using asset helpers, check out Chad Fowler’s write-up of Distributed Asset Hosts.
Sorry, the comment form is closed at this time.