Checking for a new version of an Elm app

I don’t know of any standard approaches to this, but I can share how we do it where I work, or at least how we did it last time I looked at the relevant code. This is mostly a JS (Ember) app, so there’s no Elm involved in this process, but the same techniques should work fine in Elm.

When we generate the app, we embed a unique identifier for that version in index.html, as a meta tag in the document’s head. Then in the app, we fetch index.html on a 30-minute interval, parse the version out of the header, and if it’s different than what’s currently running, prompt the user to refresh.

One nice thing about this approach is that index.html is the browser’s entry point, and all CSS and JS assets get a new URL on each release, so there’s no way for the detected version to be out of sync with the reality of what’s deployed. The downsides are that we’re fetching more data than is strictly necessary, since there’s a bunch of other information in the HTML unrelated to the version, and that pulling the data out of the HTML is a bit more complicated than it would be if we were just fetching some JSON. That said, since we have fully control over the structure of the document, we could almost certainly get away with using a regex to pull out the version rather than a full HTML parser (we might actually do that, I don’t recall).

Hopefully that’s helpful, but feel free to follow up if you’re interested in more details. I’ll be back in the office tomorrow where it’ll be easier to look up the actual code involved.

1 Like