Magento News

 

Magento – HTML minify code causing some javascript not working

I have the below code to remove white space in a Magento site.

ob_start("htmlcompress");

function htmlcompress($buffer) {
   $buffer = preg_replace('/nr|rn|n|r|t| {2}/', '', $buffer);
   return $buffer;
}

It works well, however in some areas where inline javascripts are used, the scripts stopped working. Example, in “checkout/onepage/billing.phtml”:

<script type="text/javascript">
//<![CDATA[
$('billing:region_id').setAttribute('defaultValue', "<?php
  echo $this->getAddress()->getRegionId()
?>");
//]]>
</script>

and “giftmessage/inline.phtml” where toogle function disabled; also the “payment/form/cc.phtml” where radio button for payment options.

Not all inline scripts got disabled though, for instance, anything start with “var” are working.

How I can improve the compress script to prevent javascript from stop working?

Thanks

Magento – HTML minify code causing some javascript not working

Possibly Related Posts:


 

Leave a Reply