Page 1 of 1

Cache problem with gzip compression

Posted: Sun Feb 25, 2007 7:27 am
by WaldoMonster
At the start of the script I send these two headers:

Code: Select all

header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1
header('Pragma: no-cache'); // HTTP/1.0
The server send this header to the client, And doesn’t cache anything:

Code: Select all

HTTP/1.1 200 OK
Date: Sun, 25 Feb 2007 13:12:31 GMT
Server: Apache
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Keep-Alive: timeout=15, max=97
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=ISO-8859-1
But when enabling zlib compression (zlib.output_compression = On)
IE 6 caches the same pages.
(used httpWatch to see the client caches or not)
Here is the header that the server sends:

Code: Select all

HTTP/1.1 200 OK
Date: Sun, 25 Feb 2007 13:06:41 GMT
Server: Apache
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Content-Encoding: gzip
Vary: Accept-Encoding
Content-Length: 270
Keep-Alive: timeout=15, max=96
Connection: Keep-Alive
Content-Type: text/html; charset=ISO-8859-1
Is there a way to disable caching with gzip compression enabled?

Posted: Sun Feb 25, 2007 9:17 am
by anjanesh
Have you tried

Code: Select all

header('Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0');
?

Posted: Sun Feb 25, 2007 10:23 am
by WaldoMonster
Thanks but that didn't do the trick.
I have tested many different settings for the header with these results:

Code: Select all

// Cache:
header('Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0');

// Cache:
header('Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');

// No cache:
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');

// No cache:
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');

// No cache:
header('Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
Witch from the "No cache" header settings would be most compatible with different browsers?
Is the "Pragma: no-cache" header out dated, and not needed any more?

Posted: Sun Feb 25, 2007 10:42 am
by anjanesh
Since you mentioned that IE was caching it, I came across this which is specifically for IE caching

Code: Select all

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");  // disable IE caching

Posted: Sun Feb 25, 2007 11:56 am
by feyd
It may be a silly question but did you flush IE's cache before testing the new code?

Posted: Sun Feb 25, 2007 12:48 pm
by WaldoMonster
Yes, I did flush the IE's cache.

The problem with the zlib compression is related to the AJAX get GET XMLHttpRequest.
Sorry for that :oops:

With the below header a GET XMLHttpRequest doesn't get old data,
But still stores them to the browser cache.

Code: Select all

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
I think the only real solution is to use POST XMLHttpRequest.