Cache problem with gzip compression

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Cache problem with gzip compression

Post 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?
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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');
?
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post 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?
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It may be a silly question but did you flush IE's cache before testing the new code?
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post 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.
Post Reply