question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Version hash in CSS does not match manifest and mix() output

See original GitHub issue
  • Laravel Mix Version: 6.6.6
  • Node Version: 15.5.1
  • NPM Version: 7.3.0
  • OS: macOS 11

Description:

I use mix with file versioning and I have custom fonts that I embed. These font assets get different hashes in the generated CSS files (where the fonts are defined) and in the HTML where I preload them using mix().

Steps To Reproduce:

My mixpack.mix.js looks like this:

mix.js('resources/js/app.js', 'public/js')
    .postCss('resources/css/app.css', 'public/css', [
        require('tailwindcss'),
    ]);

mix.copy('resources/img', 'public/img');
mix.copy('resources/fonts', 'public/fonts');

if (mix.inProduction()) {
    mix.version();
}

app.css imports fonts.css which has fonts defined like this:

@font-face {
    font-family: 'Rubik';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: local('Rubik Regular'),
    url('../fonts/rubik-v11-latin-regular.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
    url('../fonts/rubik-v11-latin-regular.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
}

Now in my HTML header I preload the WOFF2 fonts like this:

<link rel="preload" href="{{ mix('fonts/rubik-v11-latin-regular.woff2') }}" as="font" type="font/woff2" crossorigin>

In the compiled CSS the font URL is

url(/fonts/rubik-v11-latin-regular.woff2?1d5a416e2889e382ab1af96fef09bd16)

but in the mix manifest file it is

"/fonts/rubik-v11-latin-regular.woff2": "/fonts/rubik-v11-latin-regular.woff2?id=e21357a42764554dd5e3"

and accordingly in the HTML the mix() function will also output the URL with the hash e21357a42764554dd5e3

So the hashes in the generated CSS differ from the hashes in the manifest and in the HTML. This breaks my preloading as the file will be loaded twice.


Now am I doing something wrong or is this a bug?

Also, I would be fine with excluding all WOFF files from the versioning as they won’t change anyway. But the docs say I could either version everything or list each file separately. Is there some kind of exclusion list or a way to include entire folders? I don’t want to put every single image as a paremeter to version().

I guess a workaround would be to put absolute URLs in the CSS file so they are not versioned. But I thought there must be a better solution.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

5reactions
thecrypticacecommented, Jan 29, 2021

I’m going to re-open for me to investigate this further. Ideally the hashes generated by mix would match those by webpack but I’m not yet sure of the feasibility of that. I’ve investigated this some previously and it appears to be rather difficult.

As this isn’t strictly an error but a preloading issue this isn’t super high priority but I’ll see what I can figure out.

0reactions
stale[bot]commented, Jun 16, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Version hash in CSS does not match manifest and mix() output
I use mix with file versioning and I have custom fonts that I embed. These font assets get different hashes in the generated...
Read more >
Laravel-mix versioning when uploaded in S3 thinks in ...
Now, S3's eTag doesn't match to mix-manifest.json hash. And, when I visit the page, it fetches 1 version behind, not the latest uploaded...
Read more >
Versioning | Laravel Mix Documentation
With Mix versioning enabled, a unique querystring id will be appended to your assets every time your code is compiled. Consider the following...
Read more >
Content Security Policy Level 3 - W3C
Hash -based source expressions may now match external scripts if the script element that triggers the request specifies a set of integrity ...
Read more >
Resolving "SHA digest of the file filename does not match ...
Resolving "SHA digest of the file filename does not match manifest ", in VMware Workstation Pro 16.2.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found