added lazy loading for css and js
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<!-- JS Plugins + Main script -->
|
||||
{{ $scripts := slice }}
|
||||
{{ $scriptsLazy := slice }}
|
||||
{{ range site.Params.plugins.js }}
|
||||
{{ if findRE "^http" .link }}
|
||||
<script
|
||||
@@ -7,24 +8,39 @@
|
||||
type="application/javascript"
|
||||
{{ .attributes | safeHTMLAttr }}></script>
|
||||
{{ else }}
|
||||
{{ $scripts = $scripts | append (resources.Get .link) }}
|
||||
{{ if not .lazy }}
|
||||
{{ $scripts = $scripts | append (resources.Get .link) }}
|
||||
{{ else }}
|
||||
{{ $scriptsLazy = $scriptsLazy | append (resources.Get .link) }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
|
||||
<!-- main script -->
|
||||
{{ $scripts = $scripts | append (resources.Get "js/main.js") }}
|
||||
{{ $scripts = $scripts | resources.Concat "js/script.js" }}
|
||||
{{ $scripts = $scripts | resources.Concat "js/scripts.js" }}
|
||||
|
||||
{{ $scriptsLazy = $scriptsLazy | resources.Concat "js/scripts-lazy.js" }}
|
||||
|
||||
{{ if hugo.IsProduction }}
|
||||
{{ $scripts = $scripts | minify | fingerprint }}
|
||||
{{ $scriptsLazy = $scriptsLazy | minify | fingerprint }}
|
||||
{{ end }}
|
||||
|
||||
|
||||
{{/* scripts */}}
|
||||
<script
|
||||
crossorigin="anonymous"
|
||||
integrity="{{ $scripts.Data.Integrity }}"
|
||||
src="{{ $scripts.RelPermalink }}"></script>
|
||||
|
||||
{{/* scripts lazy */}}
|
||||
<script
|
||||
crossorigin="anonymous"
|
||||
integrity="{{ $scriptsLazy.Data.Integrity }}"
|
||||
src="{{ $scriptsLazy.RelPermalink }}"
|
||||
defer></script>
|
||||
|
||||
<!-- progressive web app -->
|
||||
{{ partialCached "pwa.html" . }}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user