Sonny Sonny - 3 months ago 7
Ajax Question

Force user to reload page

Background information:


  1. I have JavaScript that makes an AJAX request.

  2. I am using a version URL parameter to make sure that when a page loads it gets the latest version of the JavaScript file:
    /path/to/file.js?v=20160511



That problem I need to solve now is when I make a change to the data that is returned by the AJAX call (I assume this is considered an API break), and the JavaScript file (client). My first thought would be to somehow force the user to reload the page when I release a change to the API. What is a good process to make sure the client and server stay in sync?

Answer

Based on U─čurcan's comment and Hullu2000's answer, I added two things to my current implementation. The total necessary items are:

  1. The JavaScript referenced in page has a version URL parameter to make sure that when a page loads it gets the latest version of the JavaScript file: /path/to/file.js?v=20160511
  2. The API call returns a JSON response with an API version string
  3. The JavaScript checks the API response version string against a local variable. If they don't match, it calls window.location.reload();