So I have a third party javascript library that my customers inject into their site, and I want to make sure that their visitors always get the latest version of my script.
My customers shouldnt have to change their implementation, so forcing them to attach a version as a query parameter (example.com/mylibrary.js?v=3) is not acceptable.
Not caching is also not acceptable
https://example.com/MyLibrary.js
This library interacts heavily with my api on https://example.com, so sometimes after a deploy with changes to both the api and js library, the old script version isn't compatible anymore. So users with cached versions will not get the latest version of the javascript immediately, which can cause the application to break.
My customers have heavily visited sites, so I'm using cloudflare to hard cache https://example.com/MyLibrary.js and I want to minimize load on my servers while having a fully automated process of versioning.
The best plan I have so far is to make my webpack build process create a https://example.com/version.txt that includes the latest version of the script, and to rename the library output file to MyLibrary.{versionnumber}.js.
the MyLibrary.js that my customers inject will then just contain code to check the version.txt and then inject a script tag with MyLibrary.{versionnumber}.js.
Everything will be hardcached and version.txt cache purged on every deploy.
Is this impossible ? Stupid ? Is there a better way ? How does google do it with all their scripts ?