diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2016-07-15 20:14:11 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2016-07-15 20:14:11 +0200 |
commit | 72464f1ce49b16049e0c82aedf2f740b50ec1991 (patch) | |
tree | 9b54b530efba0852cd6857b1920821222d45f0b6 /lib/private/TemplateLayout.php | |
parent | e577ef87280788b788f6c38daf8e38043bbfbc8c (diff) | |
download | nextcloud-server-72464f1ce49b16049e0c82aedf2f740b50ec1991.tar.gz nextcloud-server-72464f1ce49b16049e0c82aedf2f740b50ec1991.zip |
Remove asset pipelin
Fixes #215
The asset pipeline has shown to do more harm than good. Some apps fail
hard with it. Also it makes sure that you download a huge file on each
unvisited page.
Diffstat (limited to 'lib/private/TemplateLayout.php')
-rw-r--r-- | lib/private/TemplateLayout.php | 151 |
1 files changed, 20 insertions, 131 deletions
diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 9a0fbda741d..4255c8998f6 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -137,36 +137,30 @@ class TemplateLayout extends \OC_Template { self::$versionHash = md5('not installed'); } - $useAssetPipeline = self::isAssetPipelineEnabled(); - if ($useAssetPipeline) { + // Add the js files + $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); + $this->assign('jsfiles', array()); + if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { $this->append( 'jsfiles', \OC::$server->getURLGenerator()->linkToRoute('js_config', ['v' => self::$versionHash])); - $this->generateAssets(); - } else { - // Add the js files - $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); - $this->assign('jsfiles', array()); - if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { - $this->append( 'jsfiles', \OC::$server->getURLGenerator()->linkToRoute('js_config', ['v' => self::$versionHash])); - } - foreach($jsFiles as $info) { - $web = $info[1]; - $file = $info[2]; - $this->append( 'jsfiles', $web.'/'.$file . '?v=' . self::$versionHash); - } + } + foreach($jsFiles as $info) { + $web = $info[1]; + $file = $info[2]; + $this->append( 'jsfiles', $web.'/'.$file . '?v=' . self::$versionHash); + } - // Add the css files - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); - $this->assign('cssfiles', array()); - $this->assign('printcssfiles', []); - foreach($cssFiles as $info) { - $web = $info[1]; - $file = $info[2]; + // Add the css files + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); + $this->assign('cssfiles', array()); + $this->assign('printcssfiles', []); + foreach($cssFiles as $info) { + $web = $info[1]; + $file = $info[2]; if (substr($file, -strlen('print.css')) === 'print.css') { - $this->append( 'printcssfiles', $web.'/'.$file . '?v=' . self::$versionHash); - } else { - $this->append( 'cssfiles', $web.'/'.$file . '?v=' . self::$versionHash); - } + $this->append( 'printcssfiles', $web.'/'.$file . '?v=' . self::$versionHash); + } else { + $this->append( 'cssfiles', $web.'/'.$file . '?v=' . self::$versionHash); } } } @@ -205,91 +199,6 @@ class TemplateLayout extends \OC_Template { return $locator->getResources(); } - public function generateAssets() { - $assetDir = \OC::$server->getConfig()->getSystemValue('assetdirectory', \OC::$SERVERROOT); - $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); - $jsHash = self::hashFileNames($jsFiles); - - if (!file_exists("$assetDir/assets/$jsHash.js")) { - $jsFiles = array_map(function ($item) { - $root = $item[0]; - $file = $item[2]; - // no need to minifiy minified files - if (substr($file, -strlen('.min.js')) === '.min.js') { - return new FileAsset($root . '/' . $file, array( - new SeparatorFilter(';') - ), $root, $file); - } - return new FileAsset($root . '/' . $file, array( - new JSqueezeFilter(), - new SeparatorFilter(';') - ), $root, $file); - }, $jsFiles); - $jsCollection = new AssetCollection($jsFiles); - $jsCollection->setTargetPath("assets/$jsHash.js"); - - $writer = new AssetWriter($assetDir); - $writer->writeAsset($jsCollection); - } - - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); - - // differentiate between screen stylesheets and printer stylesheets - $screenCssFiles = array_filter($cssFiles, function($cssFile) { - return substr_compare($cssFile[2], 'print.css', -strlen('print.css')) !== 0; - }); - $screenCssAsset = $this->generateCssAsset($screenCssFiles); - - $printCssFiles = array_filter($cssFiles, function($cssFile) { - return substr_compare($cssFile[2], 'print.css', -strlen('print.css')) === 0; - }); - $printCssAsset = $this->generateCssAsset($printCssFiles); - - $this->append('jsfiles', \OC::$server->getURLGenerator()->linkTo('assets', "$jsHash.js")); - $this->append('cssfiles', $screenCssAsset); - $this->append('printcssfiles', $printCssAsset); - } - - /** - * generates a single css asset file from an array of css files if at least one of them has changed - * otherwise it just returns the path to the old asset file - * @param $files - * @return string - */ - private function generateCssAsset($files) { - $assetDir = \OC::$server->getConfig()->getSystemValue('assetdirectory', \OC::$SERVERROOT); - $hash = self::hashFileNames($files); - - if (!file_exists("$assetDir/assets/$hash.css")) { - $files = array_map(function ($item) { - $root = $item[0]; - $file = $item[2]; - $assetPath = $root . '/' . $file; - $sourceRoot = \OC::$SERVERROOT; - $sourcePath = substr($assetPath, strlen(\OC::$SERVERROOT)); - return new FileAsset( - $assetPath, - array( - new CssRewriteFilter(), - new CssMinFilter(), - new CssImportFilter() - ), - $sourceRoot, - $sourcePath - ); - }, $files); - - $cssCollection = new AssetCollection($files); - $cssCollection->setTargetPath("assets/$hash.css"); - - $writer = new AssetWriter($assetDir); - $writer->writeAsset($cssCollection); - - } - - return \OC::$server->getURLGenerator()->linkTo('assets', "$hash.css"); - } - /** * Converts the absolute file path to a relative path from \OC::$SERVERROOT * @param string $filePath Absolute path @@ -304,24 +213,4 @@ class TemplateLayout extends \OC_Template { return $relativePath[1]; } - - /** - * @param array $files - * @return string - */ - - private static function hashFileNames($files) { - foreach($files as $i => $file) { - try { - $files[$i] = self::convertToRelativePath($file[0]).'/'.$file[2]; - } catch (\Exception $e) { - $files[$i] = $file[0].'/'.$file[2]; - } - } - - sort($files); - // include the apps' versions hash to invalidate the cached assets - $files[] = self::$versionHash; - return hash('md5', implode('', $files)); - } } |