Move script to head with defer attribute set. Should give optimal performance.

This commit is contained in:
Fredrik Jonsson 2019-04-09 13:18:34 +02:00
commit d8ac6ecfd0
3 changed files with 19 additions and 6 deletions

View file

@ -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)

View file

@ -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 -}}
</head>
@ -39,6 +40,5 @@
</div>
{{ if $.Param "mobilemenu" }}{{ partial "mobilemenu.html" . }}{{ end -}}
{{ partial "scripts.html" . -}}
</body>
</html>

View file

@ -1,16 +1,16 @@
{{ if $.Param "jquery" -}}
{{ $jquery := resources.Get "js/jquery.slim.min.js" | fingerprint -}}
<script src="{{ $jquery.RelPermalink }}"></script>
<script defer src="{{ $jquery.RelPermalink }}"></script>
{{ end -}}
{{ $umbrella := resources.Get "js/umbrella.min.js" | fingerprint -}}
<script src="{{ $umbrella.RelPermalink }}"></script>
<script defer src="{{ $umbrella.RelPermalink }}"></script>
{{ if $.Param "mobilemenu" -}}
{{ $mobilemenu := resources.Get "js/mobile.js" | minify | fingerprint -}}
<script src="{{ $mobilemenu.RelPermalink }}"></script>
<script defer src="{{ $mobilemenu.RelPermalink }}"></script>
{{ end -}}
{{ if $.Param "contactform" -}}
{{ $contact := resources.Get "js/contact.js" | minify | fingerprint -}}
<script src="{{ $contact.RelPermalink }}"></script>
<script defer src="{{ $contact.RelPermalink }}"></script>
{{ end -}}
{{ $script := resources.Get "js/script.js" | minify | fingerprint -}}
<script src="{{ $script.RelPermalink }}"></script>
<script defer src="{{ $script.RelPermalink }}"></script>