0

After hours, I finally found the cause why the difference of after and before count of rows does not updating inside an HTML element. It is because the external source (/count) that I call in every 5 seconds are being cached. To expand the problem, the /count page is composing of the real time number of rows. If ever a webpage is initially loaded, the function loadXMLCount takes an argument 2865 rows as its initial values. On the other hand, after 5 seconds, considering there's no row being added within 5 seconds, the /count will also have a value of 2865 row. The initial call of the function loadXMLCount will return the difference of 2865 - 2865 which is 0. On the second call, if the /count will now have 2867 rows, two rows were added between 5 - 10 seconds. The result should be 2867 - 2865 = 2. The problem I'm facing is that I can't pull the latest value of /count (2867) within the main html page. I already tried the meta header inside /count page but I had no luck. When I tried to reload the /count page the main page will also be updated (could have updated the save on disk in Chrome). How can I avoid external page to be cached or to be save on disk (I found it on Chrome dev console) and load it without forcing to reload the /count page?

<script>
    ...
    ...
    xhttp.open("GET", "/count", true);
    xhttp.send();
}
    setInterval('loadXMLCount(2865)',5000); 
</script>
Ninja Warrior 11
  • 362
  • 3
  • 17
  • Requests to the non-static resources are not cached until you use cache directly. I am not sure you found correct problem – Drag13 Jun 13 '18 at 18:57
  • @Vitalii I just added `Math.round(+new Date()/1000)` to `xhttp.open("GET", "/count?_" + Math.round(+new Date()/1000), true)`. It actually works, thanks to Scott Marcus' suggestive answer. – Ninja Warrior 11 Jun 13 '18 at 19:06
  • Great that it helps you – Drag13 Jun 13 '18 at 19:08

0 Answers0