[wp-trac] [WordPress Trac] #53232: Add async decoding attribute as default to the HTML image tags generated by WordPress

WordPress Trac noreply at wordpress.org
Fri May 21 16:00:07 UTC 2021


#53232: Add async decoding attribute as default to the HTML image tags generated by
WordPress
-----------------------------+------------------------------
 Reporter:  isaumya          |       Owner:  (none)
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Media            |     Version:
 Severity:  normal           |  Resolution:
 Keywords:                   |     Focuses:  performance
-----------------------------+------------------------------

Comment (by westonruter):

 Replying to [comment:3 ayeshrajans]:
 > Make sure kses allow-lists the decoding attribute.

 This wouldn't be necessary since the `decoding` attribute is added on the
 frontend and is not stored in the post content. The `loading` attribute is
 not stored in post content either. Nevertheless, I see `loading` was
 explicitly added to Kses so might as well add it.

 > I would suggest to only add the `decoding` attribute only if
 `loading=lazy` is also present. This ''might''(?) reduce sudden content
 reflows.

 I don't believe this is necessary. I believe the layout shifting issue is
 only relevant to lazy-loading.

 > I took a quick look at how lazy loading is currently implemented, and I
 think we should follow suit:

 Otherwise, your proposal for how to implement seems good to me!

 Replying to [comment:4 isaumya]:
 > If you have a working code snippet that will help a lot of people to add
 it right now to their WP sites until this gets added to the core code.

 This will do the trick for all images in the post content:

 {{{#!php
 <?php
 add_filter(
         'the_content',
         static function ( $content ) {
                 return str_replace( '<img ', '<img decoding=async ',
 $content );
         }
 );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53232#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list