[wp-trac] [WordPress Trac] #52990: Account for single quoted attributes when lazy loading images and iframes.

WordPress Trac noreply at wordpress.org
Fri Jun 11 00:17:37 UTC 2021


#52990: Account for single quoted attributes when lazy loading images and iframes.
------------------------------------------+------------------------------
 Reporter:  peterwilsoncc                 |       Owner:  (none)
     Type:  defect (bug)                  |      Status:  new
 Priority:  normal                        |   Milestone:  Awaiting Review
Component:  Embeds                        |     Version:  5.5
 Severity:  normal                        |  Resolution:
 Keywords:  needs-unit-tests needs-patch  |     Focuses:  performance
------------------------------------------+------------------------------
Changes (by azaozz):

 * keywords:  needs-unit-tests has-patch => needs-unit-tests needs-patch


Comment:

 The initial code in that conditional was without the double quote, `false
 === strpos( $image, ' src=' )`. That made it compatible with all attribute
 "styles" (double, single and no quotes). However that broke some inline
 js, see above comment.

 There was a patch to support single quotes, see
 https://core.trac.wordpress.org/attachment/ticket/44427/44427.10.diff
 (scroll to the middle, ~line 1715 in the patched `src/wp-
 includes/media.php`). It can be adapted to implement that support now.

 On the other hand the WordPress editor (both the block editor and TinyMCE)
 normalize HTML attributes to always use double quotes. The "template
 functions" also output HTML with double quotes.

 Yes, the conditional where the quote is checked can have false positives.
 It's purpose is to bypass adding of the `loading` attribute, i.e. if
 `src`, `width`, or `height` are missing or in case of a false positive it
 falls back to the "safe" option of not changing the tag.

 At the time #44427 was implemented it seemed that the slowdown of getting
 the quote style for each image would have larger negative impact than not
 adding the `loading` attribute when the tags attributes are with single
 quotes or no quotes.

 Now that iframes are also lazy-loaded it may make sense to look for single
 quotes and take the slowdown. Perhaps that can be only for iframes as the
 overall improvements there are quite more significant, and iframes are
 quite rare in post_content compared to images.

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


More information about the wp-trac mailing list