From 6f36c4f8e9867447874eb96b6c0dee2b04de5c74 Mon Sep 17 00:00:00 2001 From: Murilo Cruz Date: Wed, 14 Oct 2026 16:47:27 -0300 Subject: [PATCH 1/2] feat: native lazy loading for images (#300) Add an opt-in `lazyLoading` config param that sets the native loading="lazy" attribute on images, so they're only fetched when they approach the viewport. Native lazy loading never fires for images that aren't rendered, so: - while a lazy image is pending, the block stays in the "uploading" state, showing the preloader as a placeholder - in the "uploading" state the picture is kept in the layout (invisible) instead of display: none - Ui.render() no longer resets a status set before rendering to "empty" Videos (.mp4) are still loaded immediately. Co-Authored-By: Claude Opus 5.5 --- README.md | 30 ++++++++++++++++++++++++++++++ dev/index.html | 19 +++++++++++++++++++ src/index.css | 10 +++++++++- src/index.ts | 1 + src/types/types.ts | 7 +++++++ src/ui.ts | 27 ++++++++++++++++++++++++++- 6 files changed, 92 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 39e29a2..d3d32b8 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ Image Tool supports these configuration parameters: | uploader | `{{uploadByFile: function, uploadByUrl: function}}` | Optional custom uploading methods. See details below. | | actions | `array` | Array with custom actions to show in the tool's settings menu. See details below. | | features | `object` | Allows you to enable/disable additional features such as border, background tunes and caption. See details below. | +| lazyLoading | `boolean` | (default: `false`) Defers loading of images until they approach the viewport, using native `loading="lazy"`. See details below. | Note that if you don't implement your custom uploader methods, the `endpoints` param is required. @@ -295,3 +296,32 @@ var editor = EditorJS({ ... }); ``` + +## Lazy loading images + +Set `lazyLoading` to `true` to load images only when they approach the viewport, using the browser's native `loading="lazy"`. It's useful for long documents with many images, or for images served by private or paid endpoints. A preloader is shown in place of each image until it's loaded. + +```js +import ImageTool from '@editorjs/image'; + +var editor = EditorJS({ + ... + + tools: { + ... + image: { + class: ImageTool, + config: { + /** + * Load images only when they approach the viewport + */ + lazyLoading: true, + } + } + } + + ... +}); +``` + +Lazy loading applies to images only. `.mp4` sources are still loaded immediately. diff --git a/dev/index.html b/dev/index.html index 2383256..295c04b 100644 --- a/dev/index.html +++ b/dev/index.html @@ -10,6 +10,23 @@