I needed to force gzip for some administration pages (full of complex HTML tables) that were not automatically compressed for some clients, so I added this method. I'm not sure that I will force it for every page, but at least the admins page is 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 HTML was compressed at around 80KB, resulting in a 5-10-fold increase in speed loading the page.
source share