added lazy loading for css and js
This commit is contained in:
parent
0c9aef3e0f
commit
0235da7caa
@ -122,31 +122,45 @@ notAlternative = true
|
|||||||
# CSS Plugins
|
# CSS Plugins
|
||||||
[[params.plugins.css]]
|
[[params.plugins.css]]
|
||||||
link = "plugins/swiper/swiper-bundle.css"
|
link = "plugins/swiper/swiper-bundle.css"
|
||||||
|
lazy = false
|
||||||
[[params.plugins.css]]
|
[[params.plugins.css]]
|
||||||
link = "plugins/glightbox/glightbox.css"
|
link = "plugins/glightbox/glightbox.css"
|
||||||
|
lazy = true
|
||||||
[[params.plugins.css]]
|
[[params.plugins.css]]
|
||||||
link = "plugins/font-awesome/v6/brands.css"
|
link = "plugins/font-awesome/v6/brands.css"
|
||||||
|
lazy = true
|
||||||
[[params.plugins.css]]
|
[[params.plugins.css]]
|
||||||
link = "plugins/font-awesome/v6/solid.css"
|
link = "plugins/font-awesome/v6/solid.css"
|
||||||
|
lazy = true
|
||||||
[[params.plugins.css]]
|
[[params.plugins.css]]
|
||||||
link = "plugins/font-awesome/v6/icons.css"
|
link = "plugins/font-awesome/v6/icons.css"
|
||||||
|
lazy = true
|
||||||
|
|
||||||
# JS Plugins
|
# JS Plugins
|
||||||
[[params.plugins.js]]
|
[[params.plugins.js]]
|
||||||
link = "js/search.js"
|
link = "js/search.js"
|
||||||
|
lazy = false
|
||||||
[[params.plugins.js]]
|
[[params.plugins.js]]
|
||||||
link = "plugins/swiper/swiper-bundle.js"
|
link = "plugins/swiper/swiper-bundle.js"
|
||||||
|
lazy = false
|
||||||
[[params.plugins.js]]
|
[[params.plugins.js]]
|
||||||
link = "plugins/glightbox/glightbox.js"
|
link = "plugins/glightbox/glightbox.js"
|
||||||
|
lazy = true
|
||||||
[[params.plugins.js]]
|
[[params.plugins.js]]
|
||||||
link = "js/gallery-slider.js"
|
link = "js/gallery-slider.js"
|
||||||
|
lazy = true
|
||||||
[[params.plugins.js]]
|
[[params.plugins.js]]
|
||||||
link = "js/accordion.js"
|
link = "js/accordion.js"
|
||||||
|
lazy = true
|
||||||
[[params.plugins.js]]
|
[[params.plugins.js]]
|
||||||
link = "js/tab.js"
|
link = "js/tab.js"
|
||||||
|
lazy = true
|
||||||
[[params.plugins.js]]
|
[[params.plugins.js]]
|
||||||
link = "js/modal.js"
|
link = "js/modal.js"
|
||||||
|
lazy = true
|
||||||
[[params.plugins.js]]
|
[[params.plugins.js]]
|
||||||
link = "plugins/cookie.js"
|
link = "plugins/cookie.js"
|
||||||
|
lazy = true
|
||||||
[[params.plugins.js]]
|
[[params.plugins.js]]
|
||||||
link = "plugins/youtube-lite.js"
|
link = "plugins/youtube-lite.js"
|
||||||
|
lazy = true
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<!-- JS Plugins + Main script -->
|
<!-- JS Plugins + Main script -->
|
||||||
{{ $scripts := slice }}
|
{{ $scripts := slice }}
|
||||||
|
{{ $scriptsLazy := slice }}
|
||||||
{{ range site.Params.plugins.js }}
|
{{ range site.Params.plugins.js }}
|
||||||
{{ if findRE "^http" .link }}
|
{{ if findRE "^http" .link }}
|
||||||
<script
|
<script
|
||||||
@ -7,24 +8,39 @@
|
|||||||
type="application/javascript"
|
type="application/javascript"
|
||||||
{{ .attributes | safeHTMLAttr }}></script>
|
{{ .attributes | safeHTMLAttr }}></script>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
|
{{ if not .lazy }}
|
||||||
{{ $scripts = $scripts | append (resources.Get .link) }}
|
{{ $scripts = $scripts | append (resources.Get .link) }}
|
||||||
|
{{ else }}
|
||||||
|
{{ $scriptsLazy = $scriptsLazy | append (resources.Get .link) }}
|
||||||
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
|
||||||
<!-- main script -->
|
<!-- main script -->
|
||||||
{{ $scripts = $scripts | append (resources.Get "js/main.js") }}
|
{{ $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 }}
|
{{ if hugo.IsProduction }}
|
||||||
{{ $scripts = $scripts | minify | fingerprint }}
|
{{ $scripts = $scripts | minify | fingerprint }}
|
||||||
|
{{ $scriptsLazy = $scriptsLazy | minify | fingerprint }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
{{/* scripts */}}
|
||||||
<script
|
<script
|
||||||
crossorigin="anonymous"
|
crossorigin="anonymous"
|
||||||
integrity="{{ $scripts.Data.Integrity }}"
|
integrity="{{ $scripts.Data.Integrity }}"
|
||||||
src="{{ $scripts.RelPermalink }}"></script>
|
src="{{ $scripts.RelPermalink }}"></script>
|
||||||
|
|
||||||
|
{{/* scripts lazy */}}
|
||||||
|
<script
|
||||||
|
crossorigin="anonymous"
|
||||||
|
integrity="{{ $scriptsLazy.Data.Integrity }}"
|
||||||
|
src="{{ $scriptsLazy.RelPermalink }}"
|
||||||
|
defer></script>
|
||||||
|
|
||||||
<!-- progressive web app -->
|
<!-- progressive web app -->
|
||||||
{{ partialCached "pwa.html" . }}
|
{{ partialCached "pwa.html" . }}
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
<!-- plugins + stylesheet -->
|
<!-- plugins + stylesheet -->
|
||||||
{{ $styles := slice }}
|
{{ $styles := slice }}
|
||||||
|
{{ $stylesLazy := slice }}
|
||||||
{{ range site.Params.plugins.css }}
|
{{ range site.Params.plugins.css }}
|
||||||
{{ if findRE "^http" .link }}
|
{{ if findRE "^http" .link }}
|
||||||
<link
|
<link
|
||||||
@ -40,20 +41,40 @@
|
|||||||
href="{{ .link | relURL }}"
|
href="{{ .link | relURL }}"
|
||||||
{{ .attributes | safeHTMLAttr }} />
|
{{ .attributes | safeHTMLAttr }} />
|
||||||
{{ else }}
|
{{ else }}
|
||||||
|
{{ if not .lazy }}
|
||||||
{{ $styles = $styles | append (resources.Get .link) }}
|
{{ $styles = $styles | append (resources.Get .link) }}
|
||||||
|
{{ else }}
|
||||||
|
{{ $stylesLazy = $stylesLazy | append (resources.Get .link) }}
|
||||||
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ $styles := $styles | append (resources.Get "scss/main.scss" | toCSS) }}
|
|
||||||
{{ $styles := $styles | resources.Concat "css/style.css" }}
|
{{/* main style */}}
|
||||||
|
{{ $styles = $styles | append (resources.Get "scss/main.scss" | toCSS) }}
|
||||||
|
{{ $styles = $styles | resources.Concat "css/style.css" }}
|
||||||
{{ $styles = $styles | resources.PostCSS }}
|
{{ $styles = $styles | resources.PostCSS }}
|
||||||
|
|
||||||
|
{{ $stylesLazy = $stylesLazy | resources.Concat "css/style-lazy.css" }}
|
||||||
|
{{ $stylesLazy = $stylesLazy | resources.PostCSS }}
|
||||||
|
|
||||||
{{ if hugo.IsProduction }}
|
{{ if hugo.IsProduction }}
|
||||||
{{ $styles = $styles | resources.ExecuteAsTemplate "css/style.css" . | minify | fingerprint | resources.PostProcess }}
|
{{ $styles = $styles | resources.ExecuteAsTemplate "css/style.css" . | minify | fingerprint | resources.PostProcess }}
|
||||||
|
{{ $stylesLazy = $stylesLazy | resources.ExecuteAsTemplate "css/style-lazy.css" . | minify | fingerprint | resources.PostProcess }}
|
||||||
{{ else }}
|
{{ else }}
|
||||||
{{ $styles = $styles | resources.ExecuteAsTemplate "css/style.css" . }}
|
{{ $styles = $styles | resources.ExecuteAsTemplate "css/style.css" . }}
|
||||||
|
{{ $stylesLazy = $stylesLazy | resources.ExecuteAsTemplate "css/style-lazy.css" . }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
{{/* styles */}}
|
||||||
<link
|
<link
|
||||||
href="{{ $styles.RelPermalink }}"
|
href="{{ $styles.RelPermalink }}"
|
||||||
integrity="{{ $styles.Data.Integrity }}"
|
integrity="{{ $styles.Data.Integrity }}"
|
||||||
rel="stylesheet" />
|
rel="stylesheet" />
|
||||||
|
|
||||||
|
{{/* styles lazy */}}
|
||||||
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
href="{{ $stylesLazy.RelPermalink }}"
|
||||||
|
integrity="{{ $stylesLazy.Data.Integrity }}"
|
||||||
|
media="print"
|
||||||
|
onload="this.media='all'; this.onload=null;" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user