how to disable chrome cache when use chunked response

1.7k Views Asked by At

<?php
echo 'first<br>';
ob_flush();
flush();
file_get_contents("http://ttt.tt");
echo "second";

http://ttt.tt is not reachable. so in browser we can see the output "first" and then wait for "30s"/Maximum execution time of each script/ there will output "second". in IE、FF, it works ok.
but in chrome,"first" && "second" will output together.

my english is bad.i Don't know if you understand.help!!!

i also tried to disable browser's cache like this:
header("Cache-Control: no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

but problems still exist..

3

There are 3 best solutions below

0
On

Problem may be that "Pragma: no-cache" won`t work every time. The HTTP specification does not set any guidelines for Pragma response headers. Try to use "Expires".

If you need additional info, here is the link to web caching tutorial.

0
On

You don't need to disable cache. It's all about content type encoding. What I simply did was:

header('Content-Type: text/html; charset=UTF-8');

Initially it was:

header('Content-Type: text/html');

... which didn't work. Specifying "charset=UTF-8" immediately forced Chrome to render chunked responses.

0
On

One option is to add X-Content-Type-Options: nosniff.

See Chunked transfer encoding - browser behavior for a thorough explanation.