【问题标题】:Asset_pipeline in heroku using the wrong asset hash for precompiled javascriptheroku 中的 Asset_pipeline 对预编译的 javascript 使用了错误的资产哈希
【发布时间】:2013-09-26 09:24:52
【问题描述】:

我正在尝试设置我的应用程序以通过 Amazon S3/Cloudfront CDN 提供资产。它是一个 Rails 应用程序,我使用 asset_sync gem 按照 this heroku document. 实现这一目标@

我将我的项目推送到heroku,然后运行heroku run rake assets:precompile。这给了我如下所示的输出:

    I, [2013-09-20T21:19:06.506796 #2]  INFO -- : Writing /app/public/assets/application-cb6347d3ce9380e02c37364b541fd8ae.js
I, [2013-09-20T21:19:19.979570 #2]  INFO -- : Writing /app/public/assets/application-9dc3068c1bf9290c7eb0493fd36b3587.css
[WARNING] fog: followed redirect to abc123.s3-us-west-1.amazonaws.com, connecting to the matching region will be more performant
[WARNING] fog: followed redirect to abc123.s3-us-west-1.amazonaws.com, connecting to the matching region will be more performant

请注意,它为 JS 文件 cb6347d3ce9380e02c37364b541fd8ae.js 写入的哈希值是正确的(因为我也在 localhost 下的 staging 中运行了它)。

但问题是,当我在 heroku 上点击我的应用并检查源代码时,它包含的 JS 50460076f4c6eb614a44b6b17323efa7.js 与之前编译的不同...

为什么 heroku 没有选择正确的预编译资产来使用?我在本地部署并执行了所有相同的步骤,我的本地服务器毫无问题地选择了正确的 JS。

感谢您的帮助!

【问题讨论】:

    标签: heroku ruby-on-rails-4 asset-pipeline amazon-cloudfront


    【解决方案1】:

    一段时间后,我意识到这是因为之前我在本地编译了资产并推送了它。因此,Heroku 没有尝试在生产环境中进行预编译,而是使用了之前签入的旧 manifest.json。

    您可以在本地重新编译并推送它,或者运行rake assets:clobber 删除所有预编译的资产,然后提交/推送,heroku 会意识到它需要预编译。之后,它应该使用正确的清单文件并且资产应该正常显示。

    我发现这篇博文对了解情况非常有用:http://www.rubycoloredglasses.com/2013/08/precompiling-rails4-assets-when-deploying-to-heroku/

    【讨论】:

    • 这对我很有帮助。感谢您发布您找到的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-20
    • 1970-01-01
    • 1970-01-01
    • 2016-04-18
    • 1970-01-01
    相关资源
    最近更新 更多