0% found this document useful (0 votes)
33 views

How To Prevent The Cache Problem in AJAX

The document discusses how to avoid caching issues with AJAX requests. AJAX applications frequently request the same URL from the server but the browser returns a cached response instead of making a new request. To solve this, a random parameter can be added to the URL on each request to trick the browser into thinking it is a new URL that has not been cached. This forces the browser to always make a fresh request to the server.

Uploaded by

Ramzi Alqrainy
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

How To Prevent The Cache Problem in AJAX

The document discusses how to avoid caching issues with AJAX requests. AJAX applications frequently request the same URL from the server but the browser returns a cached response instead of making a new request. To solve this, a random parameter can be added to the URL on each request to trick the browser into thinking it is a new URL that has not been cached. This forces the browser to always make a fresh request to the server.

Uploaded by

Ramzi Alqrainy
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

How To Avoid Cashing AJAX ?

Ramzi Sh. Alqrainy


[email protected] 1
How to clear the cache ?
You can't actually clear the cache as it's controlled by
the browser, but you can ask how to avoid caching
AJAX ??

Ooooops, What is this problem ?

Ramzi Sh. Alqrainy


[email protected] 2
What is the problem ?
 AJAX application tends to frequently ask the server
for the same URL (a stock quote, application status
and so forth). The AJAX application expect a
response form the server while, in fact, after the
first request the browser returns the cached page
and the AJAX application does not work as
expected.

So, What is the solution ?

Ramzi Sh. Alqrainy


[email protected] 3
What is the solution ?
 Imagine yourself you can not change
HTML file. So, How to avoid caching
AJAX?
 If you want bypass the cache you can add
some random argument to the url:

What Happened ?
Ramzi Sh. Alqrainy
[email protected] 4
What happened ?
 Adding a pseudo-random parameter to the URL
the AJAX application is requesting. Doing so will
fool the browser to think this is a new page that
has not yet been cached.

 The Date().getTime(); returns a new value every


millisecond (or so), the browser thinks this is a new
page that has not been cached and requests the
URL form the server.

Ramzi Sh. Alqrainy


[email protected] 5
Thank You

Ramzi Sh. Alqrainy


[email protected] 6

You might also like