function test_Javascript() { global $thisDir; $src = file_get_contents($thisDir . '/_test_files/js/before.js'); $minExpected = file_get_contents($thisDir . '/_test_files/js/before.min.js'); $minOutput = Minify_Javascript::minify($src); $passed = assertTrue($minExpected == $minOutput, 'Minify_Javascript'); if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) { echo "\n---Output: " . strlen($minOutput) . " bytes\n\n{$minOutput}\n\n"; echo "---Expected: " . strlen($minExpected) . " bytes\n\n{$minExpected}\n\n"; echo "---Source: " . strlen($src) . " bytes\n\n{$src}\n\n\n"; } $src = file_get_contents($thisDir . '/_test_files/js/issue74.js'); $minExpected = file_get_contents($thisDir . '/_test_files/js/issue74.min.js'); $minOutput = Minify_Javascript::minify($src); $passed = assertTrue($minExpected == $minOutput, 'Minify_Javascript : Quotes in RegExp literals (Issue 74)'); if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) { echo "\n---Output: " . strlen($minOutput) . " bytes\n\n{$minOutput}\n\n"; echo "---Expected: " . strlen($minExpected) . " bytes\n\n{$minExpected}\n\n"; echo "---Source: " . strlen($src) . " bytes\n\n{$src}\n\n\n"; } }
private function minifyFile($url, $type) { $cache_name = md5($url) . ".minified.{$type}"; $cache_path = BASE_PATH . Glucose::config('cache_dir', 'template') . $cache_name; $file = $this->urlToPath($url); // Check for a cached version first if (file_exists($cache_path)) { $orig_last_modified = @filemtime($file); if ($orig_last_modified && $orig_last_modified < filemtime($cache_path)) { return Glucose::config('cache_dir', 'template') . $cache_name; } } // Minify and cache $file_contents = file_get_contents($file); $file_contents = $type === 'css' ? Minify_CSS::minify($file_contents) : Minify_Javascript::minify($file_contents); file_put_contents($cache_path, $file_contents); return Glucose::config('cache_dir', 'template') . $cache_name; }