Skip to content

Commit

Permalink
Implement Default Lazy Loading for Images with Configurable Option (#…
Browse files Browse the repository at this point in the history
…2183)

This PR introduces an enhancement to the site's image-loading strategy
by implementing lazy loading as the default behavior for all images. The
motivation behind this change is to improve the site's load times.

**Changes:**
1. **Default Lazy Loading:** By `default`, all images will now have the
`loading="lazy"` attribute.

2. **Configurable Option in `_config.yml`:** Added a new configuration
option under `lazy_loading_images.enable`.

3. **Override Capability:** For `specific images` where the user doesn't
want lazy loading, they can `override` this by directly setting the
`loading attribute` in the `image tag`.
  • Loading branch information
ZL-Asica authored and ngmarchant committed Jun 21, 2024
1 parent ca03a77 commit 7ae9132
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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

0 comments on commit 7ae9132

Please sign in to comment.