javascript - PHP - Sending gzip compressed JS/CSS -
i created style.css.php file code:
<?php $gzip = (ob_get_length() === false && !ini_get("zlib.output_compression") && ini_get("output_handler") != "ob_gzhandler" && extension_loaded("zlib") && substr_count($_server['http_accept_encoding'], 'gzip') && !headers_sent()); if(!$gzip) header('location: style.css'); header('content-type: text/css'); header('cache-control: no-cache'); header('expires: mon, 1 jan 1901 04:20:00 gmt'); ob_start('ob_gzhandler'); include "style.css"; ?>
what think? way compress js/css files? there better way this? i'm doing public app. can downloaded anyone. there people on shared hosts gzip disabled
no, not ok. there's lot of things wrong there. include, no dying after redirecting, not considering deflate method, ...
this simple php, zlib output handler automatically detects appropriate compression send client (if any); have enable it:
<?php if (extension_loaded("zlib") && (ini_get("output_handler") != "ob_gzhandler")) { ini_set("zlib.output_compression", 1); } readfile('style.css');
Comments
Post a Comment