How does finger print digest gets calculated in Rails 4.2

旧城冷巷雨未停 提交于 2020-12-10 08:56:56

问题


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.

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.

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.


回答1:


The digest seems to be built here: https://github.com/rails/sprockets/blob/master/lib/sprockets/digest_utils.rb

Looks like there's a lot of logic in there, but that's where to find the answer.

It appears that the actual hash is created by calling ADD_VALUE_TO_DIGEST[obj.class].call(obj, digest) in the build_digest method.

Good question; I learned something while looking this up.




回答2:


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

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

  1. Sprockets::VERSION.
  2. Rails.application.assets.version that is generated here (https://github.com/rails/sprockets-rails/blob/2.x/lib/sprockets/railtie.rb#L91).
  3. Compiled file content.

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



来源:https://stackoverflow.com/questions/51767418/how-does-finger-print-digest-gets-calculated-in-rails-4-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!