加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

heroku中的Asset_pipeline使用预编译的javascript的错误资产哈希

发布时间:2020-12-14 04:56:52 所属栏目:百科 来源:网络整理
导读:我正在尝试设置我的应用以通过Amazon S3 / Cloudfront CDN提供资源.它是一个rails应用程序,我使用asset_sync gem来实现这一点,按照 this heroku document. 我将我的项目推送到heroku,然后运行heroku run rake assets:precompile.这给了我看起来像这样的输出
我正在尝试设置我的应用以通过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上点击我的应用程序并检查源代码时,包含50460076f4c6eb614a44b6b17323efa7.js的JS与之前编译的JS不同…

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

谢谢你的帮助!

解决方法

过了一段时间,我意识到这是因为之前我在本地编译了资产并将其推高了.因此,Heroku没有尝试在生产中预编译,只使用之前签入的旧manifest.json.

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读