Can you review my PHP created header?
So, I'm reading through the YUI best practices for speeding up your web page, and I'm using PHP to try and implement some of those suggestions. Here is what I have so far:
<?php
// Expires one year from now
$expires = mktime(0, 0, 0, date("m"), date("d"), date("Y")+1);
// Format date
$date = date('D, d M Y 开发者_开发知识库H:i:s', $expires);
// Send HTTP header
header("Expires: $date GMT");
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
ob_start("ob_gzhandler");
else
ob_start();
?>
<!DOCTYPE ....
...
</head>
<?php flush(); ?>
<body>
...
So, does the above look good?
I have two specific questions.
- Is the
ob_start();
after theelse
necessary. If the
flush()
doing any good at all (or possibly harm?)One of the suggestions is that you flush() your page, yet another suggestion is that you GZIP your page. It makes sense that you can't flush a GZIPPED page, since the whole page is one big bundle right?
What happens if you use flush() on a page that is GZIPPED? Can anything "bad" happen? Should you keep flush() in your page for the benefit of browsers that don't accept GZIPPED content?
Thanks.
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
ob_start("ob_gzhandler");
else
ob_start();
You can simply write:
ob_start("ob_gzhandler");
It will automatically determine whether the browser supports gzip/deflate ;)
And as you enabled Output Buffering your page will be flushed as a whole chunk, therefore flush
will not have an effect. But it won't harm either. It simply will flush nothing ;)
精彩评论