Closes #21369: Add lazy loading and decoding support to ImageAttr #344

Closed
opened 2026-04-05 16:26:42 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @pheus on 2/16/2026

Fixes: #21369

Thanks for reviewing! This PR updates ImageAttr to support modern, native image performance hints in the rendered HTML.

Summary of changes

  • Adds load_lazy and decoding parameters to ImageAttr
    • load_lazy now defaults to True to enable loading="lazy" by default
    • decoding can be set to auto, async, or sync
    • If decoding is not explicitly provided, it defaults to async when load_lazy=True (and is omitted otherwise)
  • Updates the ui/attrs/image.html template to conditionally render loading and decoding attributes

Why

This helps reduce initial page load time and bandwidth usage on pages with many images, while still allowing explicit control over image decode behavior when needed.

References:

*Originally created by @pheus on 2/16/2026* ### Fixes: #21369 Thanks for reviewing! This PR updates `ImageAttr` to support modern, native image performance hints in the rendered HTML. #### Summary of changes - Adds `load_lazy` and `decoding` parameters to `ImageAttr` - `load_lazy` now defaults to `True` to enable `loading="lazy"` by default - `decoding` can be set to `auto`, `async`, or `sync` - If `decoding` is not explicitly provided, it defaults to `async` when `load_lazy=True` (and is omitted otherwise) - Updates the `ui/attrs/image.html` template to conditionally render `loading` and `decoding` attributes #### Why This helps reduce initial page load time and bandwidth usage on pages with many images, while still allowing explicit control over image decode behavior when needed. References: - `HTMLImageElement.loading`: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/loading - `HTMLImageElement.decoding`: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decoding
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#344