From: Michael M Slusarz Date: Thu, 30 Jul 2009 19:58:08 +0000 (-0600) Subject: Use simple PHP-based javascript minification. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=12141fe07d82965917a28236bc55d94545d6eb0a;p=horde.git Use simple PHP-based javascript minification. In the future, possibly allow more powerful compressors (e.g. YUI compressor). Or allow automatic compression of all files, and then piece these compressed files into a single, servable file. Any method will be better than having to manually compress the javascript files. --- diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index e8327a8a4..508c47ba6 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -310,7 +310,7 @@ HTML; foreach ($s_list as $app => $files) { foreach ($files as $file) { if ($file['d'] && ($file['f'][0] != '/') && empty($file['e'])) { - $js_tocache[$file['p'] . $file['f']] = false; + $js_tocache[] = $file['p'] . $file['f']; $mtime[] = filemtime($file['p'] . $file['f']); } elseif (!empty($file['e'])) { $js_external[] = $file['u']; @@ -342,22 +342,21 @@ HTML; if (!$exists) { $out = ''; - foreach ($js_tocache as $key => $val) { + foreach ($js_tocache as $val) { // Separate JS files with a newline since some compressors may // strip trailing terminators. - if ($val) { - // Minify these files a bit by removing newlines and - // comments. - $out .= preg_replace(array('/\n+/', '/\/\*.*?\*\//'), array('', ''), file_get_contents($key)) . "\n"; - } else { - $out .= file_get_contents($key) . "\n"; + $js_text = file_get_contents($val); + try { + $out .= Horde_Text_Filter::filter($js_text, 'JavascriptMinify') . "\n"; + } catch (Horde_Exception $e) { + $out .= $js_text . "\n"; } } switch ($cache_type) { case 'filesystem': if (!file_put_contents($js_path, $out)) { - throw new Horde_Exception('Could not write cached CSS file to disk.'); + throw new Horde_Exception('Could not write cached JS file to disk.'); } break;