Problems with cached result when sending XMLHttpRequest?

I am new to AJAX idea as well as caching.

On AJAX - send a request to the server from W3Schools, it says that you should add a "?t=" + Math.random()script to the end of the URL to prevent caching.

Wikipedia has a simple definition for "cache":

In computer science, a cache is a component that transparently stores data, so that future requests for this data can be served faster. The data stored in the cache can be values ​​that were previously calculated or duplicated by the original values, which are stored elsewhere.

But shouldn't that be better? The script will run faster if several duplicate data is already stored on the computer. Also, the first example on the tutorial page without adding a URL worked fine.

Can someone please explain the reason for using "?t=" + Math.random()?

+4
source share
3 answers

But isn't that better?

Yes, it’s better to have a caching system for performance reasons, your application pages will load quickly, because once downloaded items will be retrieved without making an HTTP request to the server each time.

Can someone please explain the reason for using "? T =" + Math.random ()?

"?t=" + Math.random() URL- script . , , , . .

, (, , ), . , -, , , , , , , . , .

, , , , ...

, , , .

+7

-, , , . , , .

, , AJAX, . http://example.com/get_high_score.php. , 100. , , 5 ( ). , 100. 125.

http://example.com/get_high_score.php?t=12345786, , .

url + "?t=" + Math.random() . , .

url + "?t=" + (new Date()).getTime()

, , (, , ), , .

+1

, . ( ) , , .

var t = new Date().getTime(); var t2 = Math.floor(t/10000); url = target_url + "?t=" + t2;

, URL-, , , " ", , , , , .

0

All Articles