public function registerScript($id, $script, $position = null, array $htmlOptions = array()) { // assumed config includes the required path aliases to use // EScriptBoost $debug = YII_DEBUG; // Check if this script is in the exceptions - if so, skip caching. foreach ($this->skipList as $s) { $skip |= strpos($id, $s) === 0; if ($skip) { break; } } $compressed = !$debug ? false : Yii::app()->cache->get($id); if ($skip) { // Skipping scripts that should not be cached. $compressed = EScriptBoost::minifyJs($script); } elseif ($debug && $compressed !== false) { // During debug check that the newly minified script is not different from the cached one. // If so, log the difference so that it can be fixed. $c = EScriptBoost::minifyJs($script); if ($c !== $compressed) { Yii::log("Issue with caching of compressed script '{$id}'\n" . CVarDumper::dumpAsString($c) . "\nXXX\n" . CVarDumper::dumpAsString($compressed), CLogger::LEVEL_ERROR); } } elseif ($compressed === false) { $compressed = EScriptBoost::minifyJs($script); Yii::app()->cache->set($id, $compressed, $this->cacheDuration); } parent::registerScript($id, $compressed, $position, $htmlOptions); }
public function registerScript($id, $script, $position = self::POS_READY) { // assumed config includes the required path aliases to use // EScriptBoost $compressed = YII_DEBUG ? $script : Yii::app()->cache->get($id); if ($compressed === false) { $compressed = EScriptBoost::minifyJs($script); Yii::app()->cache->set($id, $compressed, $this->cacheDuration); } parent::registerScript($id, $compressed, $position); }
/** * Custom copy file to compress/copy|copy files * @param string $src the full path of the file to read from * @param string $dstFile the full path of the file to write to */ public function copyFile($src, $dstFile) { // assumed config includes the required path aliases to use // EScriptBoost $ext = strtoupper(substr(strrchr($src, '.'), 1)); if ($ext == 'JS' && !$this->strpos_arr($dstFile, $this->minifiedExtensionFlags) || $this->forceCompress) { Yii::trace('copyFile JS Compressing: ' . $src, 'EAssetManagerBoost'); @file_put_contents($dstFile, EScriptBoost::minifyJs(@file_get_contents($src), EScriptBoost::JS_MIN_PLUS)); @touch($dstFile, @filemtime($src)); } else { if ($ext == 'CSS' && !$this->strpos_arr($dstFile, $this->minifiedExtensionFlags) || $this->forceCompress) { Yii::trace('copyFile CSS Compressing: ' . $src, 'EAssetManagerBoost'); @file_put_contents($dstFile, EScriptBoost::minifyCss(@file_get_contents($src))); @touch($dstFile, @filemtime($src)); } else { copy($src, $dstFile); } } }