Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable internet explorer cache using javascript or php

I have an php powered application with javascript and many jax calls. my application is working upto date in firefox. but when i run it in internet explorer-8 or similar versions my ajax call gets cached in my browser so i am not able to output the upto date info with the ajax calls instead the result for that ajax calls are served with old data's which reside in the browser cache.

 I have tried lots of possible options as listed below

1.) I added following meta tag in header files


<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>

2.)I added Following php code

header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Pragma: no-cache');

But still the above 2 approaches did not solve my problem ie, please can anybody help me to disable caching internet explorer when my application runs, so that its possible to get upto date information.

thanks in advance

like image 304
gowtham kumar Avatar asked Aug 05 '11 09:08

gowtham kumar


People also ask

How do I disable cache in Internet Explorer?

On the General tab, locate the Browsing history section, and click Settings. On the Temporary Internet Files tab, confirm that Every time I visit the webpage is selected. On the Caches and databases tab, confirm that Allow website caches and databases is not selected. Click OK.

Is JavaScript cached in browser?

In general, most modern browsers will cache JavaScript files. This is standard practice for modern browsers and ensures an optimized loading experience. Cached assets such as JavaScript will typically be served from the browser's cache instead of making another request for a resource that has already been retrieved.

How do I clear my cookies and cache in Internet Explorer 11?

In Internet Explorer, select the Tools button, point to Safety, and then select Delete browsing history. Select the Cookies and website data check box, and then select Delete.

How do I stop Ajax from caching?

ajax, which will allow you to turn caching off: $. ajax({url: "myurl", success: myCallback, cache: false});


1 Answers

Make each AJAX request unique in some way. That will prevent IE from caching the response.

For example, if your normal AJAX query URL is www.mysite.com/ajax.php?dog=cat, add in a querystring parameter to each AJAX request that is unique:

www.mysite.com/ajax.php?dog=cat&queryid=1

Increment that parameter each time you make an AJAX request, and that should hopefully do the trick for you.

like image 99
James Avatar answered Sep 29 '22 02:09

James