You are here:  » minify html output


minify html output

Submitted by tobyhage on Mon, 2017-06-12 20:49 in

Hello,

Do you know how to minify the html output (easily)?
I already use the gzip mod.

Submitted by support on Tue, 2017-06-13 08:00

Hi Toby,

The default class names could be reduced if you wished, for example "pt_sr_i_c" (or even less) in place of "pt_sr_image_container" - i've preferred to keep them descriptive as it stands for ease of template modification but that would be one option to reduce page size...

Cheers,
David.
--
PriceTapestry.com

Submitted by tobyhage on Tue, 2017-06-13 11:54

Thank you for the suggestion. Is it possible to minify the complete html output like below:

for example with this kind of code: {link saved}

{code saved}

Submitted by support on Tue, 2017-06-13 12:15

Hi Toby,

It would be no problem to use PHP's output buffering functionality to remove all redundant characters from the output (new line, carriage return and TAB) and also replace any sequences of 2 or more spaces with a single space...

You mentioned having already added gzip compression (node 1471) so the first thing to do would be to remove that (it will go back in at the end after minification) and then add the following code to the very BEGINNING of html/header.php:

<?php
  ob_start
();
?>

And then add the following code to the very END of html/footer.php:

<?php
  $html 
ob_get_contents();
  
$html str_replace(array("\n","\r","\t"),"",$html);
  
$html preg_replace('/[ ]{2,}/',' ',$html);
  
ob_end_clean();
  
ob_start("ob_gzhandler");
  print 
$html;
  exit();
?>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by tobyhage on Tue, 2017-06-13 15:20

Yes this is what i want :-). Thank you very much.