Rails asset_host,cloudfront和heroku

我正在heroku上运行一个rails 4.0应用程序,对于我的生活,我无法使用我在asset_host中设置的主机获取我的资产URL。

我相信我的云端设置很好,因为我可以在我的cloudfronturl中替换我的任何资产url,并且该文件是从heroku中获取并缓存在cloudfront上的。

所以https://xxxxxxxxxxxx.cloudfront.net/assets/application-xxxxxxxx.js正确缓存https://myapp.com/assets/application-xxxxxxxxx.js 。

问题似乎是我的资产助手,例如javascript_include_tag,永远不会在staging.rb中使用asset_host设置。

我加载页面时看到的是我所有的js和css文件都来自https://myapp.com/assets/

我的分段设置如下所示:

# Full error reports are disabled and caching is turned on config.consider_all_requests_local = false config.action_controller.perform_caching = true # Disable Rails's static asset server (Apache or nginx will already do this) config.serve_static_assets = true # Compress JavaScripts and CSS config.assets.compress = true # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = true # Generate digests for assets URLs config.assets.digest = true #config.assets.digest = false #config.assets.initialize_on_precompile = true config.static_cache_control = "public, max-age=31536000" # user Amazon Cloudfront for asset hosting config.action_controller.asset_host = "https://xxxxxxxxxxxx.cloudfront.net" 

是否有一个神奇的配置设置组合,以某种方式让我望而却步?

好的,终于弄清楚发生了什么 – 我的应用程序使用的是rails_api gem,它从标准的rails堆栈中删除了一大堆中间件。

将我的应用程序控制器更改为类ApplicationController

我接着发现的另一个问题是,rack-mini-profiler重写缓存标头总是重新validation,从而否定了cdn的大部分好处。 我现在已经在升级和生产中禁用了它,我的应用程序运行得更快!