[dokuwiki] alternative for js_compress()
- From: Alexander Krause <alexander.krause@xxxxxxxxxxxxxx>
- To: dokuwiki@xxxxxxxxxxxxx
- Date: Thu, 21 Jun 2007 00:16:49 +0200
Hi,
i just played a bit with some php-regex functions to compact .js files.
I think it might be a better solution for dokuwiki's js_compress()
(inc/js.php) too.
I tried some js files with that script:
<?php
$content=file_get_contents($_SERVER['QUERY_STRING']);
$prot_search=$prot_replace=array();
//protect strings and keywords
$content=preg_replace_callback(array('|\\"|','|\\\'|','|\".+\"|','|\'.
+\'|'),'cut_unparsed',$content);
//strip comments
$content=preg_replace(array('|/\*.*\*/|ms','|//.*$|m'),'',$content);
//protect regex
$content=preg_replace_callback('|/.+/|','cut_unparsed',$content);
//strip spaces
$content=preg_replace(array('|^\s*|m','|(\w\s+[\$\w\'%])?\s*|','|;
(\})|'),'${1}',$content);
$content=str_replace($prot_search,$prot_replace,$content);
echo $content;
function cut_unparsed($matches) {
global $prot_replace,$prot_search;
$prot_replace[]=$matches[0];
return ($prot_search[]='~'.count($prot_replace).'~');
}
?>
I'll keep the code at
http://wiki.erazor-zone.de/wiki:projects:php:js_compress .
Cheers Alex
--
e-design - Hard- & Softwaredesign
Inh. Alexander Krause
Amtmann-Kästner-Platz 11
99091 Erfurt
Mail alexander.krause@xxxxxxxxxxxxxx
Tel. +49 (179) 4725826
Fax. +49 (361) 6008915
--
DokuWiki mailing list - more info at
http://wiki.splitbrain.org/wiki:mailinglist
- Follow-Ups:
- [dokuwiki] Re: alternative for js_compress()
- From: Andreas Gohr
Other related posts:
- » [dokuwiki] alternative for js_compress()
- » [dokuwiki] Re: alternative for js_compress()
- » [dokuwiki] Re: alternative for js_compress()
- [dokuwiki] Re: alternative for js_compress()
- From: Andreas Gohr