Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Default Lazy Loading for Images with Configurable Option #2183

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,15 @@ imagemagick:
output_formats:
webp: "-quality 85"

# Lazy loading images
# If you enable lazy loading, all images will add the loading="lazy" attribute.
# This will make your site load faster, but it may not be supported in all browsers.
# You can also set loading="" to other values for specific images to override the default behavior.
# Options: "auto", "eager", "lazy"
# See https://web.dev/browser-level-image-lazy-loading/ for more information.
lazy_loading_images:
enable: true # enables lazy loading of images (recommended)

# -----------------------------------------------------------------------------
# Optional Features
# -----------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions _includes/figure.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
{% if include.zoomable %}
data-zoomable
{% endif %}
{% if include.loading %}
loading="{{ include.loading }}"
{% elsif site.lazy_loading_images.enable %}
loading="lazy"
{% endif %}
onerror="this.onerror=null; $('.responsive-img-srcset').remove();"
>
</picture>
Expand Down