/** * Минификация яваскриптов * * @return void */ public function jsAction() { $this->_response->setHeader('Content-Type', 'text/javascript', true); if (isset($this->_params['files'])) { $files = explode(',', $this->_params['files']); foreach ($files as $key => $file) { $file = $this->_jsdir . trim($file) . '.js'; if (file_exists($file)) { $files[$key] = $file; } } if (!empty($files)) { $cacheid = 'minify_js_' . md5(implode(',', $files)); $this->_cache->setMasterFiles($files); if ($this->_cache->test($cacheid)) { $this->_response->setBody($this->_cache->load($cacheid)); } else { require_once 'Phorm/Plugin/jsmin.php'; $str = ''; foreach ($files as $file) { $str .= file_get_contents($file) . PHP_EOL; } $js = JSMin::minify($str); $this->_cache->save($js, $cacheid); $this->_response->setBody($js); } } } }