Force clients to reload

Trying to deploy a new version of our app.

It works for 98%+ of end users but some clients seem to have old versions that lead to random client side error messages. Is there a mechanism to force the clients to fully reload and get the latest version?

Thank you

The forum has several posts, addressing this question from several different angles. Did you find what you needed using Forum Search?

I tried several different search queries and didn’t find anything useful. Do you have a search suggestion? I tried things like, “client invalidation”, “client cache”, etc.

Thank you

I had fair luck searching for the term you used in your title: “reload”.

I’m still not seeing an ideal solution. How does Anvil normally invalidate the client side app when a new version is pushed live? Is there a mechanism to force the clients to reload from the server side? I’d rather not reinvent the wheel if the Anvil platform already has some flavor of versioning baked in (as I would assume it already does)? Like I stated originally, this probably works 98% of the time but that 2% can be several people in our use case that are reporting spurious errors. If they load the app in an Incognito window, the problem is usually resolved (but it’s a lousy user experience and causes needless support requests).

It doesn’t. App updates can affect client-side code, server-side, or both. Updates can be entirely backwards- and/or forwards-compatible, depending on what changed and how you built your app.
So, the question of whether a running Client needs to update, or not, and how to arrange that update, is left to the developer.

If you mean, a built-in mechanism for you to use, server-side, to force your Client instances to reload, then no. The Client instance, in the browser, is always in control of itself. You can add code to your Client to make it log out, and to force a browser refresh (loading the latest Published version of itself).

def force_browser_refresh():
    """Immediately reloads App from remote server w/o saving."""
    import anvil.js.window
    anvil.js.window.location.reload(True)

However, for the Client to know when to call such code, is up to the developer.

You can explicitly “version” your App source code (by hard-coding a version number value in your source), so it will always “know” what version is running.

Database content, however, is not versioned. Therefore, you could create and reserve some database entry, to contain your “currently-supported” version number. (Or even a whole list of them.) If you did this, then each of your Client instances could periodically check to see whether it’s currently-supported.

When that check fails, then that Client instance needs to reload. But that instance’s user might need it to save their work-in-progress, first. In general, there’s no way for Anvil to tell what pre-update steps your App might need to perform. So the whole procedure is up to you.

2 Likes

Thank you! This was very helpful.

1 Like