Hello! I’m trying to setup Webpack so that it appends a fingerprint to each compiled asset. For example, image.png might be compiled to image-7d25452ceb63594739af24cde73b6499.png where the fingerprint section ( 7d..99 ) is the hash of the content of the file.
I want to do that to be able to cache assets forever. That is enabled by the fact that the name changes depending on the content.
The problem is that I’m not sure how to have Elm playing nice with that. I see that https://github.com/NoRedInk/elm-assets-loader is deprecated. Is this still a good solution? How do you approach this problem in your Elm apps?
Fingerprinting does have something to do with Elm if you have to update the filenames in your code, e.g. img [ src "/myimage.png" ] [] becoming img [ src "/myimage-a1b2c3.png" ] [] in a production build.
We handle this with a custom webpack plugin that adds the hash as a query param so that the filenames don’t change but we still get cache busting.
I understand the webpack-subresource-integrity plugin adds some attributes (e.g. integrity) to the html tags but does not touch the urls / names. I think it’s a different use case than mine. Am I mistaken?
You may also be interested reading about Webpack Manifest. Shortly, Webpack can generate a JSON file during the build process where original file names are accompanied with their hashed versions. You can load this file in your app via flags, parse it and build a dictionary of original file names and their hashed counterparts. Then it is only about taking right value from this dictionary.
You will however need to always pass this dictionary to your view functions.
I’ve decided to go the easy way, I’m importing the images in JavaScript via Webpack and then passing them to the Elm app via flags.
In other words, I’m doing what’s suggested in the docs for create-elm-app. I’d add the link but Discourse does not allow me.
Thanks everybody for the suggestions. I learned a lot by reading them!