It seems that all the browsers other than Opera cache XHR requests in my Javascript program. The URL in the XHR request refers to a CGI program on the server which generates a different output everytime its called. B Is there a way in Javascript to make the browser not cache XHR requests?
When you're in Google Chrome, click on View, then select Developer, then Developer Tools. Alternatively, you can right click on a page in Chrome, then click Inspect. Click on the Network tab, then check the box to Disable cache. You can then close out of Developer Tools.
Browser handles automatically cache of resources. What you seem to be asking about is the actuall response from the server. You will need to set that up yourself in your application. You can do so both on front-end and backend.
In compatible browsers, if msCaching is not disabled , then XMLHttpRequest instances will be cached to disk regardless of whether cache-control is set to no-cache .
Caching minimizes the number of queries that are sent to your server, which takes longer to process than cached results. This is the main reason for caching and how it may improve page performance, load time, and better user experience. While load times are crucial, caching also lowers network costs.
For every AJAX request you make, generate a unique value and add it to the ajax URL as a query parameter:
/example/url/post.php?rand=09809807896768
I use to generate the current unix timestamp in JS and use that - this ensures I do not get duplicated stamps.
That way every request is unique and will not get cached. This is a simple but fairly common AJAX trick - usually fixing IE and testing issues.
If you were to use jQuery, it does this for you by setting the property cache to false on the AJAX settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With