Credit to Jono Job for helping me achieve this solution.
What I ended up doing was the following:
In my build pipeline I added the following two lines before the client build
- sed -i -e "s/{{build-number}}/${CI_COMMIT_SHORT_SHA}/g" ./src/environments/environment.prod.ts
- echo $CI_COMMIT_SHORT_SHA > ./src/assets/build.txt
The first line pushes the commit hash into the compiled javascript bundle, the second creates a text file with the commit hash as the content.
I then set up an Angular service which uses the http client to poll the text file which contains the commit hash. It checks to see if the hash in the text file is different to the hash loaded from the javascript bundle.
The theory here is that the Javascript bundle can be cached, but the http request to fetch the build.txt file will not be. Allowing me to inspect a difference between the build hashes stored in the two.
If the service detects a difference in builds, it would project a prompt to the user notifying them of an update which, upon clicking, would refresh the page.
Refreshing is done using window.location.reload(true)
. TypeScript tells me the parameter is deprecated, though it still works.
Here's a gist of the aforementioned Angular service:
https://gist.github.com/alshdavid/032ea535f222646dc74420e20b28faa1
In my APM, I can see that within a couple of hours of pushing an update, everyone client has been updated to the latest version.
So it probably works.