Obviously been able to clearly see the generated page code is useful when designing and bug fixing but the rest of the time, during normal production, the site visitor doesn’t require lots of comments and white space which are taking extra bandwitdh and reducing efficiency.
The final regex here will not be very kind to any code that uses HTML comments inside script or style tags for example (as dreamweaver and anyone else wanting to hide scripts / styles from older browsers will put..)
<?php
// +----------------------------------------------------------------------+
// | CleanOutput |
// +----------------------------------------------------------------------+
// | Created February 2006 |
// +----------------------------------------------------------------------+
// | Author: Mark Kaplan |
// +----------------------------------------------------------------------+
$e = $modx -> Event;
$content = "";
switch ($e -> name) {
case "OnWebPagePrerender":
$content = $modx -> documentOutput;
$content = preg_replace('/\n|\r/', '', $content);
$content = preg_replace('/<!--(.|\s)*?-->/', '', $content);
$modx -> documentOutput = $content;
break;
default :
return; // stop here - this is very important.
break;
}
<?php
$content = '<script type="text/javascript">
<!--
$foo = "bar";
<!-- comment on Javascript code here -->
-->
<html stuff here>
';
$content = preg_replace('/<!--(.|\s)*?-->/s', '', $content);
echo $content;
?>
~
$content = preg_replace('/<!(.*?)(--.*?--\s*)+(.*?)>/s', '', $content);
$content = preg_replace('/-->/', '', $content);
Is it possible to run that plugin to clean the code, then have it (or another plugin) load javascript via regClientScript and/or regClientStartupScript after the cleanup?