How to force update Single Page Application (SPA) pages?

前端 未结 6 1841
生来不讨喜
生来不讨喜 2020-12-12 15:13

In fully server side based rendering (non Web 2.0), deploying server side code would directly update client side pages upon page reload. In contrast, in React based Single P

6条回答
  •  春和景丽
    2020-12-12 15:43

    Similar to Steve Taylor's answer but instead of versioning API endpoints I would version the client app, in the following way.

    With each HTTP request send a custom header, such as:

    X-Client-Version: 1.0.0

    The server would then be able to intercept such header and respond accordingly.

    If the server is aware that the client's version is stale, for example if the current version is 1.1.0, respond with an HTTP status code that will be appropriately handled by the client, such as:

    418 - I'm a Teapot

    The client can then be programmed to react to such a response by refreshing the app with:

    window.location.reload(true)

    The underlying premise is that the server is aware of the latest client version.

    EDIT:

    A similar answer is given here.

提交回复
热议问题