Repository navigation
Open
Labels
[Feature] Design ToolsTools that impact the appearance of blocks both to expand the number of tools and improve the experi[Status] In ProgressTracking issues with work in progress[Type] PerformanceRelated to performance efforts
Description
Part of #54336
As raised in #54336 (comment) and #54336 (comment) it would be good to come up with a way to optimise the image output for the background image block support which is currently used by the Group block.
Ideas discussed thus far
- For performance, an
imgelement within the Group block would be preferable as it allows bothsrcsetandloading="lazy"so that images are lazy loaded, and only an image of an appropriate size. - An
imgelement however, can't implement all features supported bybackground-image, so for example repeating backgrounds would not be able to use theimgelement approach. - If the support sometimes injects an
imgelement and sometimes doesn't, this might make it hard for the support to work well with different themes and blocks that might opt in. - If using an
imgelement, how would this work with a background image support that is enabled in global styles? For example, if all Group or Post Content blocks are set to have a particular background image and we then go to update an individual block to use a different background image, how will these play together? image-set()was discussed, however it doesn't work with width descriptors so isn't really a viable alternative to theimgelement'ssrcset, and it doesn't allow lazy loading.- Media queries could potentially be an option, however it involves injecting a
styletag, and still wouldn't support lazy loading. However we can output things to a style tag via the style engine, so it might be a possibility.
Some requirements
- The solution needs to work for a generic block support that could be opt-in for any arbitrary block without breaking anything. I.e. how would it work for consumers if sometimes their block markup is augmented by this support in an unpredictable way?
- This block support is dynamically rendered, so any optimisation would also need to be dynamic without breaking themes
- The support will eventually include block-level global styles support, so whatever happens at the individual block level needs to be compatible with any background images set in global styles
- Ideally it should "just work" out of the box, rather than involve the user having to select a particular image size
Similar and related issues
- Cover Block: Add Background Image Size Selector #19223
- Cover Block with parallax effect does not use responsive friendly srcset attribute #35290
Other ideas
This issue is a good place for dropping ideas, thoughts, questions, concerns for how we might go about implementing image optimisation for the background image block support.
Reacted by Weston Ruter and Jos Velasco
Metadata
Metadata
Assignees
Labels
[Feature] Design ToolsTools that impact the appearance of blocks both to expand the number of tools and improve the experi[Status] In ProgressTracking issues with work in progress[Type] PerformanceRelated to performance efforts
Activity
ramonjd commentedon Apr 15, 2024
I'm looking at
image-set()and I don't think we should write it off just yet. We can look at available images sizes and use a "next best guess" to determine if an image size gets a1xor2xetc. The browser will determine which one to use.As for lazy loading, there's nothing native, yet. There are WordPress plugins that lazy load background images. That kind of thing usually increases the JS footprint though.
Or we could consider preloading the images somehow via JS or in HTML.
It's worth a small test at least to judge.
I'm leaning towards the opinion that it would be best not to use an
<img>for background images, and rather try to find an acceptable way around performant delivery.<img>would be convenient for available WordPress functionality, but it would limit the CSS properties available to the editor and, therefore, to theme users.westonruter commentedon Oct 13, 2025
I've opened WordPress/performance#2216 to prototype enhancements here, namely that we should not be using the
fullsize image for thebackground-image. Instead, we should pick the smallest image size that would match the width of the container element when it is its largest (e.g. on Desktop).