zestedesavoir / zmarkdown

Live demo: https://zestedesavoir.github.io/zmarkdown/
MIT License
224 stars 52 forks source link

[zmarkdown] Lazy-load images #505

Closed StaloneLab closed 7 months ago

StaloneLab commented 7 months ago

Fixes #496

Lazy-loading for iframes was added by commit https://github.com/zestedesavoir/zmarkdown/commit/28b2196031cefd1fb8da480bf031fff2814c7187 , this PR aims at lazy-loading all images for ZMarkdown.

Since parsing of images is done by remark directly, implementation was done using a postprocessor, which adds an attribute loading=lazy for all images, except emoticons. Since these are guaranteed to be lightweight and served from our servers, I considered they could be eagerly loaded (see condition in postprocessor).

As it is the case with all postprocessors, this one can be easily disabled with a configuration option (lazyLoadImages). Since this feature should be ignored by browser not supporting it, I feel like we do not need a major version for enforcing this setting in the default configuration.

StaloneLab commented 7 months ago

Thanks @artragis , I am releasing a new version zmarkdown@11.4.0 with the recent changes.