I’d like to build my SCSS files in such way that the resulting CSS file would have a hash of it’s contents in its filename. This would me allow to set long cache values for the CSS files, which would prevent the need for HTTP roundtrips for those; if the file has changed, the the hash will be different so it isn’t in the cache. The same goes for Web Fonts.
This is something I’m already able to do with processed images, as their filename includes the hash value. Now let’s make it happen for the rest of the static resources too!
Again, I’m willing to discuss the feature and contribute a PR if this seems something the maintainers would be interested to have.
I would actually find this feature useful.
We already have https://www.getzola.org/documentation/templates/overview/#get-file-hash
I think it makes sense adding it at least for the sass files, less sure about the others. Should it be an opt-in parameter in config.toml?
Why would anyone want to turn it off? I would suggest that it is the default behavior.
They could be using webpack or other tools instead and already have hashes in their filenames.
Here’s some more thoughts:
So, there could be a function that takes a filename as input, reads the contents and hashes it, and outputs a filename that contains the hash as output. Calling that function would also “mark” that file as a file that is copied to
public using that hashed name.
What I’d also want to see is being able to customize the pattern of the output file path (this could be a
config.toml setting?), as it would make easier in some servers and services (such as Netlify) to mark the hashed files as “cacheable” using glob patterns.
Oops, I just realized that even the image filenames that I thought would be okay, don’t work this way, because the hashes are calculated only from the arguments, where the path of the original file is one, but the contents of the file isn’t. I noticed as I retouched a file a bit, and was puzzled why wouldn’t the name change.