Enable turning lazyloading on/off in settings.yml #433
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some projects don't need (or shouldn't have) lazyloaded images. This change lets us toggle lazyloading on or off from
settings.yml
.How this works:
bundle.js
, we include asettings.js
, which Jekyll populates with the lazyloading value fromsettings.yml
.settings.js
creates asettings
object which is then available for all subsequent JS. (In future, we could add other settings to this object if we need them for JS. We do something similar withlocales.js
, except there we can safely include all oflocales.yml
, whereassettings.yml
may include values that are only for site generation, and should not be exposed in client-side JS. So we are selective about which settings to include in thesettings
object.)lazyload.js
, which is also included inbundle.js
, checks whether lazyloading is activated (i.e.settings.web.images.lazyload === true
). If it isn't,lazyload.js
immediately lets all the images on the page load, without waiting for the image to scroll nearby (i.e. is skips theintersectionObserver
and changesdata-src
attributes tosrc
).