Tuesday, March 13, 2012

Faster Rails Asset Precompilation

If you have multiple Javascript assets getting compressed by Uglify, your assets:precompile step might take a long time. Mine was adding several minutes to every deployment.

The assets:precompile task actually compiles everything twice. Once with digest-based filenames, and once with plain filenames. But as long as you're careful to always use the Rails-provided asset path helpers, you don't need the plain filenames, and you can use this task instead to cut your precompilation time in half:

namespace :assets do
  namespace :precompile do
    task :digest_only do
      invoke_or_reboot_rake_task "assets:precompile:primary"
Just drop that into your lib/tasks directory and invoke it with rake assets:precompile:digest_only.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.