To disable caching files from ajax requests, you can use jQuery's
$.ajaxSetup({
cache: false
});
But how does jQuery do this? I know jQuery is a javascript library, so whatever can be done with jQuery can be done with plain javascript. So my question is: What is the javascript code that jQuery uses under the hood to turn off ajax file caching?
The easiest way to shut off browser caching of Ajax requests is with a query string parameter based on time.
This yields the following query string
The browser will see this as a different request (assuming it only makes one per microsecond) and it will request the content from the server, rather then serving it from its cache.
I think that Today's Browsers use
onunload = function(){}
just like that (yes, exactly) to prevent the Browser from caching a web page, as it was when you left it to go to another page.It's important to under stand, however, that that is not the same as the Browser's ability to remember the JavaScript loaded from your
<script type='text/javascript' src='somePage.js'></script>
tags when they have thatsrc
attribute. If you change your JavaScript on a live site, you'll want to change the name of that file, or, if the Client has not cleared their cache their Browser will attempt to load the file as it remembers it.This is the source of the cache
s is ajax's option, If you set cache false, It will add a search to you request url, The 'nonce' is jQuery.now(), It's a time; So browser will not user cache when you send ajax , request url always differenrt.
If you read the docs they say: