How can I run SOME initializers when doing a Rails assets:precompile?

前端 未结 5 1834
無奈伤痛
無奈伤痛 2021-02-04 03:55

Background

I have an app that I recently updated to Rails 3.2.1 (from Rails 3.0.x) and have refactored the JS and CSS assets to make use of the new asset pipeline. Th

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-04 04:26

    Definitely check out asset_sync on github. Or our Heroku dev centre article on Using a CDN asset Host with Rails 3.1 on Heroku.

    The issues with environment variables have recently been solved by a Heroku labs plugin, that makes your application's heroku config variables accessible during compilation time. To enable this, read about the user_env_compile plugin.

    Also. There is quite a big performance improvement in using asset_sync vs letting your application lazily compile assets in production or serving them precompiled directly off your app servers. However I would say that. I wrote it.

    • With asset_sync and S3 you can precompile assets meaning all the assets are there ready to be served on the asset host / CDN immediately
    • You can only require the :assets bundle in application.rb on precompile, saving memory in production
    • Your app servers are NEVER hit for asset requests. You can spend expensive compute time on, you know. Computing.
    • Best practice HTTP cache headers are all set by default
    • You can enable automatic gzip compression with one extra config

提交回复
热议问题