Search code examples
javascriptajaxurlget

Why do I have to avoid cached results?


I am new in AJAX and I find this one very confusing. Please help me figure it out. I pursue the curriculum of w3schools and I got this example from here:

https://www.w3schools.com/xml/ajax_xmlhttprequest_send.asp

I didn't understand what is the difference between cached file and non cached file in these two examples because both examples deliver the same results and why do I have to add a unique Id to the url?

enter image description here


Solution

  • If you request an url, the browser or other proxys on the way to the server might cache the result, so if you request it more than once, it will be delivered faster. But the content might get out of date.

    If you change the url, the caching mechanism between, from browser and other proxys on the way, will not recognize the request as the former request. If you keep sending the same number, it might get cached, so it has to be unique.

    But you cannot avoid a cached result from the server itself