CSS Cache Busting with your Git Commit SHA
When not using MIX and its versions
Now that Tailwind CSS has JIT mode, I have stopped configuring and using laravel mix.
A useful feature of mix is cache busting - the ability to force your users to reload css and js files from the server instead of using their cached versions
A simple way to add cache busting to your css loads is to use your Git commit sha hash as a parameter on the css line.
This article describes how you can get the Git sha hash in your application; https://talltips.novate.co.uk/laravel/versioning-your-laravel-project
Add the sha to your css load;
1
<link rel="stylesheet" href="/css/app.css?{{ config('version.hash') }}">
Copied!
This generates a line in your browser like;
1
<link rel="stylesheet" href="/css/app.css?f7509a3">
Copied!
where `f7509a3` is the sha hash of your code and will change on each commit.
Last modified 30d ago
Copy link