Every Rails developer know that asset loading may be really time-consuming. Here are some useful tips on how to speed it up.
Do not bundle everything into one large file. Use CDN for tools like CKeditor and require only on those pages where is needed.
I18n-js keeps the translations in a separate file. Configure only required languages, otherwise translations file may growth up very fast along with every new library. Doing so you'll avoid large compiled files which means faster compilation and page load.
Do not userequirerequire_treeandrequire_selfin your SASS/SCSS files. They are very primitive and do not work well with Sass files. Instead, use Sass's native@importdirective which sass-rails has customized to integrate with the conventions of your Rails projects. https://github.com/rails/sass-rails#important-note
In your SASS/SCSS files use@importdirective carefully. Avoid importing the whole package assets as@import 'compass';when you can only do@import 'compass/css3/flexbox'.
Avoid usingrequire_tree .directive in your JS/COFFEE manifests. Let's imagine scenario when your app has an admin panel with separate assets:
Check logs while compiling your assets. It's easy to override the default logger and see whats going on under the hood by accessing DEBUG mode.
# /lib/tasks/assets.rakerequire'sprockets/rails/task'Sprockets::Rails::Task.new(Rails.application) do |t|
Above rules can help you out with getting your compiled assets faster! As a proof of concept please take a look at cintrzyk/sprockets-tips where you can find a sample Rails app with some more details.
Since Rails 5.1 there are other ways to manage assets. I highly recommend to use Yarn with Webpack, its worth it, believe me! What you can gain is assets dependencies management, more efficient compilation process, hot-reloads your code without page refresh, ES6 support, PostCSS and many more!