What are the ways that you can speed up the Rails Asset Pipeline precompile process?
The Rails asset pipeline provides an assets:precompile rake task to allow assets to be compiled and cached up front rather than compiled every time the app boots. There are two ways you can use the asset pipeline on Heroku. Compiling assets locally.
The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB. Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets.
Capistrano has its own built-in task 'deploy/assets'. It will automatically do task for you.
The difference between your own handcraft task is it only load assets
group to precompile assets, not whole environment.
cd /home/apps/APP_NAME/releases/20120708184757 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile
https://gist.github.com/3072362
If
are changed, it will recompile assets. Otherwise, it will skip the pecompile process, save a lot of time.
@import "compass";
directly.It will both work when you
@import "compass";
or @import "compass/typography/links/link-colors";
in SCSS.
But @import "compass/typography/links/link-colors";
is 9 times faster than @import "compass";
when you compile assets.
That is because when @import "compass";
, it compile whole compass assets. not only just link-colors
part.
In SCSS, we like to use partial
to organize our assets.
But only if you need to share variables, or there are necessary dependencies, otherwise
//= require "reset" //= require "base" //= require "product"
is faster than
@import "reset"; @import "base"; @import "product";
When we use Rails generator to generate controllers. Rails will also generate assets likes this
and mount assets in application.js using this techniques:
//= require_tree
But the empty assets (output nothing) which only contain this lines:
# Place all the behaviors and hooks related to the matching controller here. # All this logic will automatically be available in application.js. # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
It will cost you about 250ms to compile each of them. If you have 10 empty assets, it will be 2.5 seconds .
Remove them from your project, or mount them individually in application.js like this:
//= require prodcuts //= require users //= require albums
css.scss
or js.coffee
if unnecessary.custom.css
is custom.css.scss
Compile pure CSS and pure JS is fast ( cost almost 0 ms). But compile .scss and .coffee still cost some time.
check logs/production.log
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With