diff options
Diffstat (limited to 'lib/minimizer.php')
-rw-r--r-- | lib/minimizer.php | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/lib/minimizer.php b/lib/minimizer.php index 9f9ef086c4a..e17c114f065 100644 --- a/lib/minimizer.php +++ b/lib/minimizer.php @@ -1,17 +1,6 @@ <?php -abstract class OC_Minimizer -{ - protected $files = array(); - - protected function appendIfExist($root, $webroot, $file) { - if (is_file($root.'/'.$file)) { - $this->files[] = array($root, $webroot, $file); - return true; - } - return false; - } - +abstract class OC_Minimizer { public function getLastModified($files) { $last_modified = 0; foreach($files as $file_info) { @@ -26,14 +15,30 @@ abstract class OC_Minimizer abstract public function minimizeFiles($files); - public function output($files) { + public function output($files, $cache_key) { header('Content-Type: '.$this->contentType); OC_Response::enableCaching(); $last_modified = $this->getLastModified($files); OC_Response::setLastModifiedHeader($last_modified); - $out = $this->minimizeFiles($files); - OC_Response::setETagHeader(md5($out)); + $gzout = false; + $cache = new OC_Cache_FileGlobal(); + if (!OC_Request::isNoCache() && (!defined('DEBUG') || !DEBUG)){ + $gzout = $cache->get($cache_key.'.gz'); + OC_Response::setETagHeader(md5($gzout)); + } + + if (!$gzout) { + $out = $this->minimizeFiles($files); + $gzout = gzencode($out); + $cache->set($cache_key.'.gz', $gzout); + } + if ($encoding = OC_Request::acceptGZip()) { + header('Content-Encoding: '.$encoding); + $out = $gzout; + } else { + $out = gzdecode($gzout); + } header('Content-Length: '.strlen($out)); echo $out; } |