note 71073 deleted from function.ob-start by cmb
| From: | cmb@php.net | Date: | Sun, 14 Jul 2019 11:21:49 +0000 |
| Subject: | note 71073 deleted from function.ob-start by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211568@lists.php.net to get a copy of this message | ||
Note Submitter:
----
I'm sure some of you more brilliant minds could pare this down some more, but using the method
found at fiftyfoureleven.com for compressing, I got my 10090-byte stylesheet down to 3536 bytes and
then again down to 2713 bytes, by stripping unecessary characters from the stylesheet. 2 ob_start
calls and the CSS file is now 73% smaller. YMMV.
<?php
ob_start("ob_gzhandler");
ob_start("compress");
header("Content-type: text/css; charset: UTF-8");
header("Cache-Control: must-revalidate");
$off = 0; # Set to a reaonable value later, say 3600 (1 hr);
$exp = "Expires: " . gmdate("D, d M Y H:i:s", time() + $off) . " GMT";
header($exp);
function compress($buffer) {
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer); // remove
comments
$buffer = str_replace(array("\r\n", "\r", "\n", "\t",
' ', ' ', ' '), '', $buffer); // remove tabs, spaces,
newlines, etc.
$buffer = str_replace('{ ', '{', $buffer); // remove unnecessary spaces.
$buffer = str_replace(' }', '}', $buffer);
$buffer = str_replace('; ', ';', $buffer);
$buffer = str_replace(', ', ',', $buffer);
$buffer = str_replace(' {', '{', $buffer);
$buffer = str_replace('} ', '}', $buffer);
$buffer = str_replace(': ', ':', $buffer);
$buffer = str_replace(' ,', ',', $buffer);
$buffer = str_replace(' ;', ';', $buffer);
return $buffer;
}
require_once('screen.css');
require_once('layout.css');
require_once('custom.php');
require_once('titles.css');
require_once('bus.css');
?>