Static Website Subresource Integrity and Text File Line Endings

When I was creating this site and playing around with Hugo, I encountered this issue for the Anatole theme. Hugo is thorough enough when it minifies resource files to add ‘integrity’ attributes with calculated checksums for the minified files.

Now when you’re using GitHub pages or another web host that serves the content out of a Git repository, it turns out the operating system that the web host is running actually matters. That is, it matters if you’re developing on a different one. A bug/feature of Git is that it can magically change the line endings of text files it checks out, to match the local operating system convention. If you have built your static site on Windows, pushed it to GitHub, and the GitHub Pages host server then checks out the site on a Linux host, the line endings on the resource files might be different - which will invalidate the checksums!

My solution was to check in a ‘.gitattributes’ file to the GitHub Pages repository, which tells git to force CSS files to always be checked out with the same line endings:

*.css text eol=crlf