Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In an isomorphic single page application, what happens to clients when you deploy new server code?

I think it's implicit that when implementing an isomorphic single page app that you've also developed a private api that your client will hit for updates.

My question is, when you push code changes to your server, there will be "stale" clients out there that are still running your old client code, and then hit your api with a possibly incompatible parameters and assumptions.

I see two possible solutions:

  1. Version your api. Your client code will have to hit the api with its current version number; your server code gets bloated with versioning logic.
  2. Implement some kind of sockets/push messaging to tell clients to do a full-page refresh to get the latest deployed code whenever a deployment occurs. (Do these connections even remain intact after a server deployment?)

(Api versioning is a necessity if you also have mobile app clients to support, but for just a web site, seems like a lot of unnecessary work.)

Anyone else encounter or solve this problem? Are there other options I'm missing?

like image 393
thien Avatar asked Jul 18 '15 20:07

thien


People also ask

What are single-page applications What are the advantages of single-page applications over the typical multi page multi URL applications?

A single-page application is a more modern approach to app development. It was used by Google, Facebook, Twitter, etc. A SPA is an app that works inside a browser and does not require page reloading during use. On the other hand, a multiple page application is considered a more classical approach to app development.

How does a single page application work?

An SPA (Single-page application) is a web app implementation that loads only a single web document, and then updates the body content of that single document via JavaScript APIs such as XMLHttpRequest and Fetch when different content is to be shown.

What is isomorphic web applications?

An isomorphic app is a web app that blends a server-rendered web app with a single-page application. On the one hand, we want to take advantage of fast perceived performance and SEO-friendly rendering from the server.


1 Answers

I would suggest a combination of the two techniques. I would recommend versioning the API, and then having a version check that gets executed by the server on ever API call. If the version is not equal to the latest version you send a message back to the client that notifies them to do a full refresh.

This way your code shouldn't get bloated with a bunch of different versioning logic. You can just create a validate function that gets called at the beginning of every call and returns a message to update if the client is out of date.

like image 178
Mike G Avatar answered Oct 21 '22 21:10

Mike G