简体   繁体   中英

Rails Application - Using Cloudfront for asset delivery with Heroku

The situation

I couldn't get my vendor assets to precompile in heroku without specifying each individual file to precompile in config/initializers/assets so resorted to setting

config.assets.compile = true

Note: I didn't require vendor assets in application.js because I'm calling them on a per page basis when they are needed.

Anyhow I setup a Cloudfront account and now everything is working as it does in development. But on deploy to Heroku, there is a warning and a link that leads to a StackOverflow post, warning against setting config.assets.compile to true.

Compile Set to True in Production If you have enabled your application to config.assets.compile = true in production, your application might be very slow. This was best described in a stack overflow post:

When you have compile on, this is what happens: Every request for a file in /assets is passed to Sprockets. On the first request for each and every asset it is compiled and cached in whatever Rails is using for cache (usually the filesystem). On subsequent requests Sprockets receives the request and has to look up the fingerprinted filename, check that the file (image) or files(css and js) that make up the asset were not modified, and then if there is a cached version serve that.

This setting is also known to cause other run-time instabilities and is generally not recommended. Instead we recommend either precompiling all of your assets on deploy (which is the default) or if that is not possible compiling assets locally.

My question is, Since I'm now using Cloudfront, does that cover me from what they are warning about, slowness etc.?

Thanks in advance for any advice :)

Yes, you're likely covered. The request for an asset will hit CloudFront first. After the first request, it will be cached and shouldn't hit your server for compilation. Every time your assets change, however, they'll have to recompile, which is of course very slow.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM