Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Want to save a bit of bandwidth?


FalseDawn

Recommended Posts

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

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

  • 4 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...