Search code examples
ruby-on-railsrubyassetsproduction

rake assets:precompile is slow in production


My ruby on rails app take about half an hour to complete a deployment. The longest step is

RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile

which takes about 1073155ms

I have to wait for a long time for each deployment.

I use

ckeditor
rails_admin

I guess it is them who slow down my deployment, but I don't evidence and I don't know how to

solve it, either.

My other environments are as follows:

rails 4.0.3
ruby 2.1.1

My production.rb about assets is

config.serve_static_assets = false

# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = true

# Generate digests for assets URLs.
config.assets.digest = true

# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'

Solution

  • Try to skip compiling ckeditor assets

    config/environments/production.rb

      require_relative '../../lib/assets/selective_assets_compressor'
      config.assets.js_compressor = SelectiveAssetsCompressor.new
    

    lib/assets/selective_assets_compressor.rb

    class SelectiveAssetsCompressor < Uglifier
      def initialize(options = {})
        super(options)
      end
    
      def compress(string)
        if string =~ /CKSource/
          string
        else
          super(string)
        end
      end
    end