how to prevent the cache problem in ajax

6
How To Avoid Cashing AJAX ? 1 Ramzi Sh. Alqrainy [email protected]

Upload: ramzi-alqrainy

Post on 24-Jan-2015

3.482 views

Category:

Education


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: How to prevent the cache problem in AJAX

How To Avoid Cashing AJAX ?

1

Ramzi Sh. Alqrainy

[email protected]

Page 2: How to prevent the cache problem in AJAX

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 ?

2

Ramzi Sh. Alqrainy

[email protected]

Page 3: How to prevent the cache problem in AJAX

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 ?

3

Ramzi Sh. Alqrainy

[email protected]

Page 4: How to prevent the cache problem in AJAX

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 ?

4

Ramzi Sh. Alqrainy

[email protected]

Page 5: How to prevent the cache problem in AJAX

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.

5

Ramzi Sh. Alqrainy

[email protected]

Page 6: How to prevent the cache problem in AJAX

Thank You

Ramzi Sh. Alqrainy

[email protected] 6