summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAditya Telange <21258296+adityatelange@users.noreply.github.com>2021-03-27 13:16:10 +0530
committerAditya Telange <21258296+adityatelange@users.noreply.github.com>2021-03-27 13:16:10 +0530
commit2fea5a10623dbaa82c17d44dd42f8514707e1429 (patch)
tree0ea167a732485569c5eb4eeb8c0b18bcfca29419
parent009d3a2e1d74603e58c6983df33798ea6d01abd5 (diff)
add browser-level lazy loading to cover images
amend to c353447
-rw-r--r--layouts/partials/cover.html6
1 files changed, 3 insertions, 3 deletions
diff --git a/layouts/partials/cover.html b/layouts/partials/cover.html
index 5ff16bc..6f932f9 100644
--- a/layouts/partials/cover.html
+++ b/layouts/partials/cover.html
@@ -11,19 +11,19 @@
{{- $processableFormats := (slice "jpg" "jpeg" "png" "tif" "bmp" "gif") }}
{{- $prod := (hugo.IsProduction | or (eq .Site.Params.env "production")) }}
{{- if (and (in $processableFormats $cover.MediaType.SubType) (ne .Site.Params.cover.responsiveImages false) (eq $prod true)) }}
- <img srcset="{{- range $size := $sizes -}}
+ <img loading="lazy" srcset="{{- range $size := $sizes -}}
{{- if (ge $cover.Width $size) -}}
{{ printf "%s %s" (($cover.Resize (printf "%sx" $size)).Permalink) (printf "%sw ," $size) -}}
{{ end }}
{{- end -}}{{$cover.Permalink }} {{printf "%dw" ($cover.Width)}}"
sizes="(min-width: 768px) 720px, 100vw" src="{{ $cover.Permalink }}" alt="{{ $alt }}" />
{{- else }}{{/* Unprocessable image or responsive images disabled */}}
- <img src="{{ (path.Join .RelPermalink .Params.cover.image) | absURL }}" alt="{{ $alt }}">
+ <img loading="lazy" src="{{ (path.Join .RelPermalink .Params.cover.image) | absURL }}" alt="{{ $alt }}">
{{- end }}
{{- else }}{{/* For absolute urls and external links, no img processing here */}}
{{- if $addLink }}<a href="{{ (.Params.cover.image) | absURL }}" target="_blank"
rel="noopener noreferrer">{{ end -}}
- <img src="{{ (.Params.cover.image) | absURL }}" alt="{{ $alt }}">
+ <img loading="lazy" src="{{ (.Params.cover.image) | absURL }}" alt="{{ $alt }}">
{{- end }}
{{- if $addLink }}</a>{{ end -}}
{{/* Display Caption */}}