[英]Rails asset_host, cloudfront and heroku
我正在 heroku 上運行一個 rails 4.0 應用程序,並且在我的一生中,我無法使用我在 asset_host 中設置的主機來獲取我的資產 URL。
我相信我的 cloudfront 設置很好,因為我可以在我的 cloudfront url 中替換我的任何資產 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 < ActionController::Base 添加回所需的中間件,並且 asset_host 立即開始工作。 我將進一步調查以確定它是哪個中間件,並決定我是否想回到 rails_api。
然后我發現的另一個問題是 rack-mini-profiler 重寫緩存頭以始終重新驗證,從而抵消了 cdn 的大部分好處。 我現在已經在 staging 和 prod 中禁用了它,我的應用程序運行得更加迅速!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.