note 71073 added to function.ob-start
| From: | php-general at lists dot php dot net | Date: | Fri, 10 Nov 2006 18:34:25 +0000 |
| Subject: | note 71073 added to function.ob-start | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119591@lists.php.net to get a copy of this message | ||
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');
?>
----
Server IP: 64.71.164.2
Probable Submitter: 71.233.85.144
----
Manual Page -- http://www.php.net/manual/en/function.ob-start.php
Edit -- https://master.php.net/note/edit/71073
Del: integrated -- https://master.php.net/note/delete/71073/integrated
Del: useless -- https://master.php.net/note/delete/71073/useless
Del: bad code -- https://master.php.net/note/delete/71073/bad+code
Del: spam -- https://master.php.net/note/delete/71073/spam
Del: non-english -- https://master.php.net/note/delete/71073/non-english
Del: in docs -- https://master.php.net/note/delete/71073/in+docs
Del: other reasons-- https://master.php.net/note/delete/71073
Reject -- https://master.php.net/note/reject/71073
Search -- https://master.php.net/manage/user-notes.php