What is the best way to find out if the current loaded version of an SPA is the latest one that is deployed? I would like to refresh the page when a new version is deployed or at least notify the user that a new version is available. I think I could probably make a netlify function that talked to the API to figure this out but it seems like something that might be built in somewhere?
You could do something as simple as checking your release version in package.json - then display a message to refresh or let users know a new version is available.
Thats my go to in the past - its the least amount of work.
So, you’re running the old version and the new version has a new package.json, but that isn’t deployed. How does it check it? Also, it requires me to update the package.json but I really just want this to work when netlify redeploys successfully.
I ended up writing a simple lambda to check the published date so you could store it and periodically compare. Seems like something that could be included in the default deploy.
Unless your users leave your SPA open in their browsers through several of your deploys, I would expect them to get the latest version from our CDN nodes the next time they access it. Here’s an article about how our caching works which may explain in more detail:
But now that you have that lambda, you should be able to confirm/deny that that’s the case by seeing if or how often you need to refresh. Would be super interesting to hear what you find!
Let us know if this helps, if you have other questions, or if I totally misunderstood the question
They leave the browser open for days and days at a time. I’ve added an api call that checks the current version every 10 min and then automatically refreshes the application if it is out of date.
Ah yes, that changes everything. I think your solution is a great one in that case. We don’t have anything built-in that would accomplish the same thing.