What is the difference between using ob_start()
and ob_start('ob_gzhandler')
?
How does it affect the page speed ?
This doesn't affect page speed in the sense you'd might think.
the ob_gzhandler is a callback function which takes the contents from your output buffer and compresses the data before outputting it.
This reduces the size of the content being sent to the browser which might speed up the content transfer to the client. But it doesn't speed up your application/website.
I needed to force gzip for some admin pages (full of complicated HTML tables) that weren't being automatically compressed for some clients so I added this method. I'm not sure I would force it for every page, but at least the admin pages its fine.
function force_gzip()
{
// Ensures only forced if the Accept-Encoding header contains "gzip"
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
{
header('Content-Encoding: gzip');
ob_start('ob_gzhandler');
}
}
950Kb of HTML was compressed down around 80KB resulting in a 5-10x speed increasing loading the page.
© 2022 - 2024 — McMap. All rights reserved.