Jan Deinhard
Jan Deinhard

Reputation: 20205

Rails: Why do asset fingerprints differ depending on where the assets are compiled?

I'm running

RAILS_ENV=staging bundle exec rake assets:precompile

on two different machines and get different fingerprints for the same asset files. I have Rails 4.0.2 installed on both machines. The machines are

Shouldn't the fingerprints be the same no matter on which machine the assets are compiled?

EDIT: The Linux machine is an EC2 instance. So I made an AMI of it and launched a second instance. Compiling the asset on this identical instance results in the same fingerprints as created on the original instance. It seems to be a 'problem' with my development machine.

Upvotes: 7

Views: 818

Answers (2)

Jay Dorsey
Jay Dorsey

Reputation: 3662

I found some additional info on a related post here that's probably more relevant regarding how checksums are calculated: How does finger print digest gets calculated in Rails 4.2

I'm also leaving my original answer below because I think it's still relevant:

I think this is behavior is working as designed. Sprockets may have changed since the time this question was asked, but I think this code comment might explain why:

    # Caveat: Digests are cached by the path's current mtime. Its possible
    # for a files contents to have changed and its mtime to have been
    # negligently reset thus appearing as if the file hasn't changed on
    # disk. Also, the mtime is only read to the nearest second. It's
    # also possible the file was updated more than once in a given second.

On my macos System:

pry > File.mtime("Rakefile").to_i
=> 1605021933

On a remote Linux server, with the exact same file pushed up:

pry > File.mtime("Rakefile").to_i
=> 1606847789

In my case, I've noticed the mtime of my files get modified/updated locally (macos) for reasons that aren't clear to me. I think it's caused either by a vim plugin I'm using (fzf? an indexing tool? I haven't researched it)

If you do an MD5 on these two files they're identical though.

tldr; The assets may be identical, but the hash appears to include other information which could vary from system to system

Upvotes: 1

DevDude
DevDude

Reputation: 385

One possible reason is that the contents may not really be the same for the same file on Mac OS X and Linux. The line feeds and carriage return characters are not handled the same way in Linux and Max OS X.

Try the same experiment with precompile the assets on different Macs to confirm if the Macs generate the same fingerprint.

Upvotes: 0

Related Questions