You are reading an old article on an old site. It only still exists so the information is not lost. Comments and mosts links are hidden and disabled.

Weird Firefox cache issue (imagetoolbar)

While testing some pages that were supposed to cached for five minutes in Firefox (3.6.3, Win32) we noticed the pages weren't being cached properly. It seemed Firefox would only cache the page once, in other words, reload the page every other request. After some more investigation it seems to be once every second, though I'm honestly not 100% sure that is exactly what happens.

We had found other references on the internet to this problem, but not the solution. After scratching our heads a few times, going through the cache headers again and again, we started removing parts of the HTML code from the response to see if it made a difference, and guess what, it did.

Older versions of Internet Explorer (6, 7) overlay an image toolbar over images that allows you to save, print, etc the image you are hovering the mouse over. This is often turned off using the following code:

Code
#
1
<meta http-equiv="imagetoolbar" content="no" />

This seems to be the cause of the issue. The following is a PHP script that demonstrates the issue:

Code
#
1
<?php
2
  header('Cache-Control: public,max-age=360,s-maxage=360');  
3
  header('Expires: '.gmdate('D, d M Y H:i:s',time()+360).' GMT');
4
?>
5
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
6
"http://www.w3.org/TR/html4/strict.dtd">
7
<html>
8
<head>
9
<title>FireFox imagetoolbar cache test</title>
10
<meta http-equiv="imagetoolbar" content="no" />   
11
</head>
12
<body>
13
 
14
Some random number: <?=rand(1,10000)?><br />
15
<br />
16
<a href="<?=$_SERVER['REQUEST_URI']?>">Reload (from cache)</a>
17
 
18
</body>
19
</html>

(Our test server reports the Date header in GMT, not sure how this works if your server reports something else)

Repeatedly clicking the link in our version of Firefox shows you a new random number every second.

One solution is using the following HTML instead of the highlighted line:

Code
#
1
<!--[if lte IE 7]>
2
  <meta http-equiv="imagetoolbar" content="no" />
3
<![endif]-->

This uses an Internet Explorer specific conditional comment. In Internet Explorer 7 and older (imagetoolbar seems to be removed from 8 and up) the imagetoolbar will be turned off, and other browsers will simply ignore it as an HTML comment.

It solved the issue for us.