Caching AJAX-requests in IE

Our company, like many other developers have had problems with IE. This browser gives us a lot of difficults in HTML and CSS, but its not the end of IE problems. We have found that IE make cashing with AJAX-requests. We have found two ways to resolve this problem. First in PHP, you can send a header from the server that the content is outdated. You can disable cashing with:
<?php
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0"false);
// HTTP/1.0
header("Pragma: no-cache");
?>
But this method is not very usefull in some cases, so the second way is the simliest and best method to resolve this problem. You can just add random variable or timestamp to your request.
  1. var url="example.com/example?uniq=" + Math.random();
OR
  1. var url="example.com/example?uniq=" + new Date().getTime();
This will make your AJAX-request unique and IE will not make cashing for it.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
Image CAPTCHA
Enter the characters shown in the image.