0

I have a bunch of external javascript libraries in my Rails project which are all included in the application.js, so they are precompiled on every deployment to Heroku, which runs for a long time.

Do you have any suggestions how to decrease the asset compilation time, and if possible, without the use of CDN.

Thanks.

ssuljic
  • 1,081
  • 1
  • 9
  • 26

1 Answers1

0

For future reference, here are the steps how I solved it:

  1. Add the external assets in the appropriate folder, vendor/assets/javascripts or vendor/assets/stylesheets
  2. Move the asset imports from the application manifest to app/assets/javascripts/external.js or app/assets/stylesheets/external.css.scss
  3. Change the config.assets.precompile line in config/application.rb to config.assets.precompile = ['external.js', 'external.css'] (note the = instead of +=)
  4. Run rake assets:precompile
  5. Remove the manifest.yml from public/assets since it indicates to Heroku if it should compile the assets or not
  6. Push the generated public/assets folder to the source control
  7. Change the config.assets.precompile line back to what it was

This way, the external.js and external.css are compiled localy and the application.js and application.css compile while deploying. The deployment time is more than two times faster now in my case. It does take some manual work, but could be implemented as a rake.

ssuljic
  • 1,081
  • 1
  • 9
  • 26
  • I wrote a blog post with a better approach than doing it manually https://crondev.com/decrease-deployment-time-of-rails-applications-by-precompiling-external-assets-separately/ – ssuljic Jan 19 '16 at 17:53