How does finger print digest gets calculated in Rails 4.2
Asked Answered
A

2

4

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.

Astolat answered 9/8, 2018 at 12:44 Comment(0)
A
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

Astolat answered 9/8, 2018 at 15:43 Comment(0)
O
4

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.

Owensby answered 9/8, 2018 at 15:27 Comment(0)
A
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

Astolat answered 9/8, 2018 at 15:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.