From cb5004031ec3dcb82064efbc4b893a5c575f6ddd Mon Sep 17 00:00:00 2001 From: Ere Maijala <ere.maijala@helsinki.fi> Date: Thu, 9 Jul 2020 21:19:30 +0300 Subject: [PATCH] Collect Cart scripts and several others to a single block. This cleans up and compresses the result by putting all the small scripts to a single block. --- .../bootstrap3/templates/layout/layout.phtml | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/themes/bootstrap3/templates/layout/layout.phtml b/themes/bootstrap3/templates/layout/layout.phtml index e10c16ce210..65ab39a7fbd 100644 --- a/themes/bootstrap3/templates/layout/layout.phtml +++ b/themes/bootstrap3/templates/layout/layout.phtml @@ -25,6 +25,9 @@ <?=$this->headLink()?> <?=$this->headStyle()?> <?php + // Collect small scripts together and append as one block: + $appendScripts = []; + if (!isset($this->renderingError)) { // Add translation strings $this->jsTranslations()->addStrings( @@ -72,21 +75,15 @@ $this->headScript()->appendFile("cart.js"); $domain = $cart->getCookieDomain(); if (!empty($domain)) { - $this->headScript()->appendScript( - 'VuFind.cart.setDomain("' . $domain . '");' - ); + $appendScripts[] = 'VuFind.cart.setDomain("' . $domain . '");'; } $cookiePath = $cart->getCookiePath(); if (!empty($cookiePath)) { - $this->headScript()->appendScript( - 'VuFind.cart.setCookiePath("' . $cookiePath . '");' - ); + $appendScripts[] = 'VuFind.cart.setCookiePath("' . $cookiePath . '");'; } $cookieSameSite = $cart->getCookieSameSite(); if (null !== $cookieSameSite) { - $this->headScript()->appendScript( - 'VuFind.cart.setCookieSameSite("' . $cookieSameSite . '");' - ); + $appendScripts[] = 'VuFind.cart.setCookieSameSite("' . $cookieSameSite . '");'; } $this->jsTranslations()->addStrings( [ @@ -110,8 +107,7 @@ // Session keep-alive if ($this->keepAlive()) { - $this->headScript()->appendScript('var keepAliveInterval = ' - . $this->keepAlive()); + $appendScripts[] = 'var keepAliveInterval = ' . $this->keepAlive() . ';'; $this->headScript()->appendFile("keep_alive.js"); } @@ -134,12 +130,13 @@ $root = rtrim($this->url('home'), '/'); $translations = $this->jsTranslations()->getJSON(); $dsb = DEFAULT_SEARCH_BACKEND; - $setupJS = <<<JS + $appendScripts[] = <<<JS VuFind.path = '{$root}'; VuFind.defaultSearchBackend = '{$dsb}'; VuFind.addTranslations({$translations}); JS; - $this->headScript()->appendScript($setupJS); + $this->headScript()->appendScript(implode("\n", $appendScripts)); + if ($this->config()->ajaxCoversEnabled()) { $this->headScript()->appendFile("covers.js"); } -- GitLab