FalseDawn Posted May 4, 2005 Share Posted May 4, 2005 Find the following in application_top.php: // if gzip_compression is enabled, start to buffer the output if ( (GZIP_COMPRESSION == 'true') && ($ext_zlib_loaded = extension_loaded('zlib')) && (PHP_VERSION >= '4') ) { if (($ini_zlib_output_compression = (int)ini_get('zlib.output_compression')) < 1) { if (PHP_VERSION >= '4.0.4') { ob_start('ob_gzhandler'); } else { include(DIR_WS_FUNCTIONS . 'gzip_compression.php'); ob_start(); ob_implicit_flush(); } } else { ini_set('zlib.output_compression_level', GZIP_LEVEL); } } Directly after, add this: function callback($buffer) { return preg_replace(array('/<!--(.|\s)*?-->/','/>( )*?</'),array('','><'), str_replace(array("\n", "\t", chr(13)), array('','',''), $buffer)); } ob_start("callback"); It'll strip HTML comments, newlines,tabs and spaces between ">" and "<" from the generated HTML. It should work with any cache classes since ob_start() can be nested. Note - if you use spaces for formatting betwwen > and < tags, these will be removed (you should be using anyway) benefits can be up to 1K per page, depending on content. Obviously more beneficial for high usage sites with bandwidth concerns. Usual disclaimers apply - i.e. use it on a test site first and don't blame me if anything breaks... Oh, and it needs php 4.0.5 or greater, or you'll have to break the str_replace up into separate commands. Link to comment Share on other sites More sharing options...
Wendy James Posted May 4, 2005 Share Posted May 4, 2005 Works great, thanks! Wendy James Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep. Link to comment Share on other sites More sharing options...
Guest Posted May 4, 2005 Share Posted May 4, 2005 FWIW, very similar functionality is part of Bobby's page cache contrib. -jared Link to comment Share on other sites More sharing options...
FalseDawn Posted May 4, 2005 Author Share Posted May 4, 2005 I just noticed that it breaks the default OSC "create account" page - maybe due to nested javascript comments or something silly. I have no intention of bug-fixing issues like this, so I strongly suggest it is _thoroughly_ tested on _every_ page on your site if you intend to use it in a live environment. Link to comment Share on other sites More sharing options...
FalseDawn Posted May 5, 2005 Author Share Posted May 5, 2005 OK, please don't use this - it strips javascript code between<script> tags, which needs to be sorted. Basically, if the page uses javascript, it won't work... Link to comment Share on other sites More sharing options...
Lucky Bastard Posted June 1, 2005 Share Posted June 1, 2005 Anybody able to fix this so that javascript isn't stipped out? Would love to know as this is vey handly code, except for that 1 obvious flaw. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.