/** * Minify Javascript. * * @param string $js Javascript to be minified * @return string */ public static function minify($js) { $jsmin = new JSmin($js); return $jsmin->min(); }
protected static function _removeScriptCB($m) { $openScript = $m[1]; $js = $m[2]; // remove HTML comments (and ending "//" if present) $js = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $js); // remove CDATA section markers $js = self::_removeCdata($js); // minify $jsmin = new JSmin($js); $js = $jsmin->min(); return self::_reservePlace(self::_needsCdata($js) ? "{$openScript}/*<![CDATA[*/{$js}/*]]>*/</script>" : "{$openScript}{$js}</script>"); }