From 80a47290a7a01f2a320d09d387eea690ce1f62b4 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 6 Aug 2012 20:34:51 +0200 Subject: do not recompress already minified js FS#2574 --- lib/exe/js.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'lib/exe/js.php') diff --git a/lib/exe/js.php b/lib/exe/js.php index f84c07709..634e21207 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -102,8 +102,12 @@ function js_out(){ // load files foreach($files as $file){ + $ismin = (substr($file,-7) == '.min.js'); + echo "\n\n/* XXXXXXXXXX begin of ".str_replace(DOKU_INC, '', $file) ." XXXXXXXXXX */\n\n"; + if($ismin) echo "\n/* BEGIN NOCOMPRESS */\n"; js_load($file); + if($ismin) echo "\n/* END NOCOMPRESS */\n"; echo "\n\n/* XXXXXXXXXX end of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n"; } @@ -262,7 +266,18 @@ function js_compress($s){ if($ch == '/' && $s{$i+1} == '*' && $s{$i+2} != '@'){ $endC = strpos($s,'*/',$i+2); if($endC === false) trigger_error('Found invalid /*..*/ comment', E_USER_ERROR); - $i = $endC + 2; + + // check if this is a NOCOMPRESS comment + if(substr($s, $i, $endC+2-$i) == '/* BEGIN NOCOMPRESS */'){ + $endNC = strpos($s, '/* END NOCOMPRESS */', $endC+2); + if($endNC === false) trigger_error('Found invalid NOCOMPRESS comment', E_USER_ERROR); + + // verbatim copy contents, trimming but putting it on its own line + $result .= "\n".trim(substr($s, $i + 22, $endNC - ($i + 22)))."\n"; // BEGIN comment = 22 chars + $i = $endNC + 20; // END comment = 20 chars + }else{ + $i = $endC + 2; + } continue; } -- cgit v1.2.3 From e71b260a0446cb34eacbd16234691eca41feb9b1 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Tue, 18 Sep 2012 00:10:23 +0200 Subject: Simplify js_compress() for regular expressions FS#2593 This simplifies a while loop in the js_compress() code. The functionality of the new code is completely identical to the old code but it uses less comparisons and according to FS#2593 it is thus a lot faster. --- lib/exe/js.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lib/exe/js.php') diff --git a/lib/exe/js.php b/lib/exe/js.php index 634e21207..42979eeed 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -301,10 +301,8 @@ function js_compress($s){ // now move forward and find the end of it $j = 1; while($s{$i+$j} != '/'){ - while( ($s{$i+$j} != '\\') && ($s{$i+$j} != '/')){ - $j = $j + 1; - } if($s{$i+$j} == '\\') $j = $j + 2; + else $j++; } $result .= substr($s,$i,$j+1); $i = $i + $j + 1; -- cgit v1.2.3