Reputation: 2694
We use a standard rails server, and on each release our application.js version is auto-changed as required
A standard refresh of the page if there is a fresh deploy will fetch the required file. No problems so far.
Now, we have a dashboard which has a refresh button, which triggers an ajax request (stats/data) and refreshes a portion of the page. No reload of a page required. But what is happening is sometimes the client doesn't reload the page throughout the day and during the time, we've deployed the latest code which is consuming the data differently, and the ajax request (stats/data) though still a valid url, now gives a weird error on the page, as that code is obsolete and data is being consumed differently.
What are the standard solutions to such a problem?
a) Was wondering if we could use sockets to inform client of the need to reload page etc, after every deploy
b) Some way we could use http caching (no-validate etc), to inform the user that the request is no longer valid and they need to reload the page.
*Not even sure what it does, and will it work. On our ajax requests, it was not even going inside the if block.
application_controller.rb
before_filter :set_cache_buster
def set_cache_buster
if request.xhr?
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end
end
Any suggestions are welcome...Looks really bad when I have to tell my client, hey please refresh the page it will work after that. If we're doing something wrong, please let me know.
Upvotes: 0
Views: 520
Reputation: 95047
Bottom line is you have to inform the client, in one way or another, that it needs to refresh. You can do this through headers sent with ajax requests, a flag sent with ajax requests, websockets, etc, but it has to come from somewhere.
The alternative would be to have either your client or your server be backwards compatible at all times. I prefer this option as it has the least impact on the client, however, when this isn't feasible, i go with websockets or ajax request headers if I don't already have a websocket server setup for that api.
Example process for websocket solution:
* by different enough I mean, for example, it doesn't need to restart for 1.0.0 to 1.0.1, but it does for 1.0.0 to 1.1.0
Upvotes: 1