0

I have this little Javascript to read a json file and it works fine the first time I run it, but if I manually change the contents of the json file and then reload the page it keeps showing me the original contents. Can you please tell me what am I missing or what should I do to make sure fresh data is going to be read after every page reload? Many thanks in advance

This is my code

<html>
   <head>
      <script type="text/javascript" language="JavaScript">
        function CheckForUpdate ()
        {
            // API for get requests
            let fetchRes = fetch("https://www.fakehost.com/fakedir/filedata");

            fetchRes.then(res =>
                res.json()).then(d => {
                    var lastUpdated = d.updated;
                    alert (lastUpdated);
            })
        }   
      </script>
   </head>
 
   <body>
      <script type="text/javascript" language="JavaScript">
    CheckForUpdate ();
      </script>
   </body>
</html>

and this is the contents of the filedata.json file

{
  "updated": 4
}
  • 2
    Speculation: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expires – Quentin Apr 13 '22 at 12:44
  • 2
    Maybe this on can help you: [javascript - fetch(), how do you make a non-cached request? - Stack Overflow](https://stackoverflow.com/questions/29246444/fetch-how-do-you-make-a-non-cached-request) – chrwahl Apr 13 '22 at 12:57
  • Many thanks for your input, using the first approach {cache: "no-store"} it is working fine now. I should have performed a better search before asking my question. – Simon Schvartzman Apr 13 '22 at 13:16

0 Answers0