Rails 不在生产中使用消化后的资产
Rails not using digested assets in production
我有一个 Rails 4.2 应用程序,它是 Heroku 上的 运行 预编译资产。我们正在尝试迁移到新平台 (Aptible),但使用相同的设置,我们的应用程序无法再正确获取资产。是的,我 运行 bundle exec rake assets:precompile
预编译资产并验证它们可用。
我让服务器打印了一些值
- puts Rails.application.assets.find_asset('application.css').digest_path
- puts stylesheet_link_tag 'application'
并且它具有正确的资产价值,但是 stylesheet_link_tag 生成了错误的 link。
[web0] application-2c5efa873b0d0254861e6a7ee25995dd.css
[web0] <link rel="stylesheet" media="screen" href="https://<something>.cloudfront.net/stylesheets/application.css" />
显然,当我们在 Heroku 上 运行 时有些不同,但是配置文件设置相同,gems 等也是如此。这是我们 [=31] 的相关部分=] 配置文件
App::Application.configure do
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = true
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_files = true
config.static_cache_control = 'public, max-age=2592000'
# Compress JavaScripts and CSS.
# config.assets.css_compressor = :sass
config.assets.js_compressor = :uglifier
config.assets.js_compressor = Uglifier.new(mangle: false)
config.assets.compile = false # Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.digest = true # Generate digests for assets URLs.
config.assets.version = '2.0' # Version of your assets, change this if you want to expire all your assets.
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = "https://#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
config.action_mailer.asset_host = config.action_controller.asset_host = 'https://<something>.cloudfront.net'
end
我在网上搜索,但我找到的唯一建议是设置
config.assets.compile = true
,这确实解决了问题,但也会导致服务器在部署后尝试加载页面时超时。
有人知道这里出了什么问题吗?为什么要寻找非摘要资产?
谢谢!
部署后您可能需要运行生产环境中的预编译任务。
我假设 Heroku 默认会这样做。
这里有几个例子:
我有一个 Rails 4.2 应用程序,它是 Heroku 上的 运行 预编译资产。我们正在尝试迁移到新平台 (Aptible),但使用相同的设置,我们的应用程序无法再正确获取资产。是的,我 运行 bundle exec rake assets:precompile
预编译资产并验证它们可用。
我让服务器打印了一些值
- puts Rails.application.assets.find_asset('application.css').digest_path
- puts stylesheet_link_tag 'application'
并且它具有正确的资产价值,但是 stylesheet_link_tag 生成了错误的 link。
[web0] application-2c5efa873b0d0254861e6a7ee25995dd.css
[web0] <link rel="stylesheet" media="screen" href="https://<something>.cloudfront.net/stylesheets/application.css" />
显然,当我们在 Heroku 上 运行 时有些不同,但是配置文件设置相同,gems 等也是如此。这是我们 [=31] 的相关部分=] 配置文件
App::Application.configure do
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = true
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_files = true
config.static_cache_control = 'public, max-age=2592000'
# Compress JavaScripts and CSS.
# config.assets.css_compressor = :sass
config.assets.js_compressor = :uglifier
config.assets.js_compressor = Uglifier.new(mangle: false)
config.assets.compile = false # Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.digest = true # Generate digests for assets URLs.
config.assets.version = '2.0' # Version of your assets, change this if you want to expire all your assets.
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = "https://#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
config.action_mailer.asset_host = config.action_controller.asset_host = 'https://<something>.cloudfront.net'
end
我在网上搜索,但我找到的唯一建议是设置
config.assets.compile = true
,这确实解决了问题,但也会导致服务器在部署后尝试加载页面时超时。
有人知道这里出了什么问题吗?为什么要寻找非摘要资产?
谢谢!
部署后您可能需要运行生产环境中的预编译任务。
我假设 Heroku 默认会这样做。
这里有几个例子: