This commit is contained in:
andrzej 2024-11-15 23:40:57 +01:00
parent a719edef94
commit ad5ecbd595
1 changed files with 4 additions and 4 deletions

View File

@ -1,5 +1,5 @@
+++
date = '2024-11-13T14:24:21+01:00'
date = '2024-11-14T14:24:21+01:00'
draft = false
title = 'Invalidating the browser cache'
tags = ['css','html','linux']
@ -34,7 +34,7 @@ Of course there is.
Look at this:
```html
<link rel="stylesheet" href="css/defaults.css?2"/>
<link rel="stylesheet" href="css/defaults.css?v=2"/>
```
As I'm requesting the file via http, I can append a query. Awesome. Not awesome enough though. I'm too lazy to edit this line of code every time I push a commit, and, being human, I'll probably forget at a critical moment. This can only mean one thing: it's time to bash (🤣) out a quick build script.
@ -43,7 +43,7 @@ As I'm requesting the file via http, I can append a query. Awesome. Not awesome
```bash
#!/usr/bin/env bash
COMMIT="$(git rev-parse HEAD)"
sed -i "s/css?=\w*/css?${COMMIT}/g" index.html
sed -i "s/css?v=\w*/css?${COMMIT}/g" index.html
```
Let's talk about what's happening here:
@ -56,7 +56,7 @@ Now, whenever we push a new commit, any CSS imports in `index.html` will be chan
```html
<link rel="stylesheet"
href="css/styles.css?=ab184410c10c1adfb8b85b03b316f72b"
href="css/styles.css?v=ab184410c10c1adfb8b85b03b316f72b"
/>
```
Now I just need to add the build script to my Jenkinsfile...