From d8ac6ecfd071b7e54c36ffc522e3838c471c7157 Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson Date: Tue, 9 Apr 2019 13:18:34 +0200 Subject: [PATCH] Move script to head with defer attribute set. Should give optimal performance. --- README.md | 13 +++++++++++++ layouts/_default/baseof.html | 2 +- layouts/partials/scripts.html | 10 +++++----- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fe03f13..f65b2ba 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,19 @@ This is originally a port of the [Zen](https://www.drupal.org/project/zen) theme * Umbrella JS 3 (tiny jQuery replacement, 2.5kB when gzipped) +## Performance + +Performance should be excellent. + +* Minimal and compliant HTML5 +* Styles 17,7 kB (4,3 kB when gzipped) +* JavaScript 8,4 kB (2,7 kB when gzipped) +* All scripts loaded in head with "defer" +* Optimised for HTTP/2 + +Some performance tools will complain about to many files (js and css files are not concatenated) but with HTTP/2 that can be ignored. + + ## Sites using the Hugo Zen theme * [Combonetwork development](https://combonet.se/) (multilingual) diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index f613789..00b6256 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -8,6 +8,7 @@ {{- partial "meta.html" . -}} {{- partialCached "styles.html" . -}} {{ block "header" . }}{{ end }} +{{ partial "scripts.html" . -}} {{ if and .Site.Params.piwikTrackerUrl .Site.Params.piwikSiteID }}{{ partialCached "matomo.html" . }}{{ end -}} @@ -39,6 +40,5 @@ {{ if $.Param "mobilemenu" }}{{ partial "mobilemenu.html" . }}{{ end -}} -{{ partial "scripts.html" . -}} diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html index 5a9980b..c2a281f 100644 --- a/layouts/partials/scripts.html +++ b/layouts/partials/scripts.html @@ -1,16 +1,16 @@ {{ if $.Param "jquery" -}} {{ $jquery := resources.Get "js/jquery.slim.min.js" | fingerprint -}} - + {{ end -}} {{ $umbrella := resources.Get "js/umbrella.min.js" | fingerprint -}} - + {{ if $.Param "mobilemenu" -}} {{ $mobilemenu := resources.Get "js/mobile.js" | minify | fingerprint -}} - + {{ end -}} {{ if $.Param "contactform" -}} {{ $contact := resources.Get "js/contact.js" | minify | fingerprint -}} - + {{ end -}} {{ $script := resources.Get "js/script.js" | minify | fingerprint -}} - +