Rails 4.2 如何计算指纹摘要 [英] How does finger print digest gets calculated in Rails 4.2

查看:41
本文介绍了Rails 4.2 如何计算指纹摘要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Rails 4.2,文档 指出指纹是根据编译文件的内容计算的 md5 摘要.

I am using Rails 4.2 and the document states that the fingerprint is an md5 digest calculated based on the content of the compiled file.

如果我们拿一个文件来说 application-4c697a2e67b1a921abbdc1f753c465d8.js4c697a2e67b1a921abbdc1f753c465d8 是 md5 摘要.问题是我们永远无法通过从同一文件的内容生成 md5 来获得相同的值.

If we take a file lets say application-4c697a2e67b1a921abbdc1f753c465d8.js, 4c697a2e67b1a921abbdc1f753c465d8 is the md5 digest. The problem is that we are never able to get the same value by generating md5 from the content of the same file.

我在某处读到此指纹不仅基于文件,还受环境以及链轮版本的影响.

I have read somewhere that this fingerprint is not only based on the file but also affected by the environment along with the version of sprockets.

有人可以解释或列出用于生成此指纹的内容(除了文件内容)吗?如果有人可以从 rails sprockets repo(最好是 sprockets 2.12.5) 这将非常有帮助.

Can someone explain or list down the things (apart from the content of the file) that are used to generate this fingerprint ? And if someone can add a reference from rails sprockets repo (preferably sprockets 2.12.5) that would be very helpful.

推荐答案

这适用于 Rails 4.2.x 不确定其他版本

This is true for Rails 4.2.x not sure about other versions

针对文件生成 md5 涉及三个部分(按相同顺序连接).

There are three parts (concatenated in the same order) involved in generating an md5 against a file.

  1. 链轮::版本.
  2. 此处生成的 Rails.application.assets.version (https://github.com/rails/sprockets-rails/blob/2.x/lib/sprockets/railtie.rb#L91).
  3. 编译的文件内容.

链轮 2.x 中的实际摘要计算(用于捆绑资产)在此处完成 捆绑资产#L30

The actual digest calculation in sprockets 2.x (for bundled assets) is being done here BundledAsset#L30

这篇关于Rails 4.2 如何计算指纹摘要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆