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

2

7

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

  • Mac OS 10.9.2 and
  • Ubuntu Linux 12.04

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.

Tidy answered 17/4, 2014 at 7:47 Comment(1)
really good question. I had a flick through sprockets and couldn't see where the digests were being generated, so now I want to know.Greenlee
C
1

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

Coonskin answered 2/12, 2020 at 14:8 Comment(0)
T
0

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.

Topo answered 22/4, 2014 at 4:38 Comment(1)
I tried with two different Linux EC2 instances. Same fingerprints on both instances. The affected files are not just text files. Most are PNG files. So I guess the carriage return characters should not matter here.Tidy

© 2022 - 2024 — McMap. All rights reserved.