Make WordPress Core

Opened 10 months ago

Closed 8 months ago

Last modified 7 months ago

#58892 closed enhancement (fixed)

Integrate `decoding="async"` logic into `wp_get_loading_optimization_attributes()`

Reported by: flixos90's profile flixos90 Owned by: pereirinha's profile pereirinha
Milestone: 6.4 Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch, has-unit-tests, has-dev-note
Focuses: performance Cc:

Description

The wp_get_loading_optimization_attributes() function was added in WordPress 6.3 as a central way to apply loading attributes to specific elements/tags. One of the attributes that WordPress core has supported since 6.1 (see #53232) is decoding="async". This attribute is currently still manually applied, instead it should be applied as part of the new function going forward.

This ticket's implementation should be considered blocked by #58891 as making the changes before that would be unnecessarily complicated and error-prone.

Attachments (1)

Screenshot 2023-09-27 at 10.17.51.png (144.3 KB) - added by spacedmonkey 8 months ago.

Download all attachments as: .zip

Change History (30)

#1 @flixos90
10 months ago

With [56347] committed, this effort is now unblocked. Please refer to the latest codebase for any changes to wp_get_loading_optimization_attributes().

#2 @flixos90
10 months ago

  • Owner set to pereirinha
  • Status changed from new to assigned

This ticket was mentioned in PR #4991 on WordPress/wordpress-develop by @pereirinha.


9 months ago
#3

  • Keywords has-patch has-unit-tests added

## What's in:

  • [x] Moved the decoding attribute of theimg tag into wp_get_loading_optimization_attributes();
  • [x] Deprecation of wp_img_tag_add_decoding_attr() and it's filters;
  • [x] Add and update tests relevant to the ticket

Trac ticket: 58892

@mukesh27 commented on PR #4991:


9 months ago
#4

Have you get decoding attribute in content images?

#5 @mukesh27
9 months ago

  • Keywords changes-requested added

Thanks @pereirinha for the PR. It's a great beginning. I've provided some feedback that you might want to take into account.

@pereirinha commented on PR #4991:


9 months ago
#6

@mukeshpanchal27 @joemcgill

Thanks for your comments. I'm actively working on them and pushing updates frequently.
I'll comment when I'm done so you can circle back on this.

@pereirinha commented on PR #4991:


9 months ago
#7

Thank you all for the feedback. I'll be working on it.

@pereirinha commented on PR #4991:


9 months ago
#8

Thanks, @mukeshpanchal27 @joemcgill @felixarntz, for all the comments so far.

I left you some comments back, where it made sense, and updated the code. There are still some pieces I'm trying to wrap my head around, and a quick call would be very helpful to clear them.

If it makes sense, let's talk on Slack and try to conciliate a time for it.

This ticket was mentioned in Slack in #core-performance by pereirinha. View the logs.


9 months ago

This ticket was mentioned in Slack in #core-performance by pereirinha. View the logs.


8 months ago

This ticket was mentioned in Slack in #core-performance by flixos90. View the logs.


8 months ago

This ticket was mentioned in Slack in #core-performance by flixos90. View the logs.


8 months ago

#13 @flixos90
8 months ago

  • Keywords needs-dev-note added

The 4 tickets related to wp_get_loading_optimization_attributes() should receive a single dev note post explaining those changes.

This ticket was mentioned in Slack in #core by oglekler. View the logs.


8 months ago

This ticket was mentioned in Slack in #core-performance by pereirinha. View the logs.


8 months ago

#16 @flixos90
8 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 56690:

Media: Rely on wp_get_loading_optimization_attributes() to add decoding="async" to images.

The wp_get_loading_optimization_attributes() function was introduced in 6.3, as a single centralized place to control loading optimization attributes for various tags, most importantly images.

This changeset consolidates the decoding="async" optimization, which was added in 6.1, to occur solely as part of wp_get_loading_optimization_attributes(), removing duplicate code and allowing centralized filtering based on [56651].

As part of the change, the wp_img_tag_add_decoding_attr() function has been deprecated. The filter of the same name continues to be maintained for backward compatibility, as before covering only images that are part of a content blob such as post content (the_content).

Props pereirinha, mukesh27, joemcgill, flixos90.
Fixes #58892.
See #53232.

#18 @flixos90
8 months ago

  • Keywords changes-requested removed

#19 @spacedmonkey
8 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopenning, as this commit resulted in a notice error. See attached screenshot.

This ticket was mentioned in Slack in #core-performance by spacedmonkey. View the logs.


8 months ago

This ticket was mentioned in PR #5331 on WordPress/wordpress-develop by @pereirinha.


8 months ago
#21

This PR fixes a regression introduced on #58892 when moving the responsibility for the decoding attribute to the wp_get_loading_optimization_attributes.

This will add the decoding attribute to the get_avatar(). As trunk currently is, this context will fail to get any optimization attributes while running the_content filter.

Trac ticket: #58892

This ticket was mentioned in PR #5331 on WordPress/wordpress-develop by @pereirinha.


8 months ago
#22

This PR fixes a regression introduced on #58892 when moving the responsibility for the decoding attribute to the wp_get_loading_optimization_attributes.

This will add the decoding attribute to the get_avatar(). As trunk currently is, this context will fail to get any optimization attributes while running the_content filter.

Trac ticket: #58892

#23 @pereirinha
8 months ago

This Slack thread holds more information about the reopening and discussion around the source of the issue and mitigatory measures.

In sum, there's a regression introduced here https://github.com/WordPress/wordpress-develop/pull/4991/commits/828130034c5a7790ed8e53660b34eeaf214b4e0d#diff-2dd87d67e80339[…]3df894da4462e69L2848/, where the default value for decoding was removed.
As you see, I also removed it in various other places, and I wasn't able to get any issues. The reason for that is that we get the decoding attribute via the wp_get_loading_optimization_attributes() that we ran after.

The problem with the gravatar is that it is requested within the context of get_avatar, but when we are doing the the_content filter. This will fail this check so we end up without the decoding attribute.

The recommendation is to bring the decoding attribute as a default value as it was for the get_avatar(), but I don't think we need to bring the other ones.

An alternative approach suggested by @spacedmonkey is to move the setting of the decoding attribute before the context checks, as this argument has a different type of impact than lazy loading and fetchpriority.

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


8 months ago

This ticket was mentioned in Slack in #core-performance by mukeshpanchal27. View the logs.


8 months ago

@pereirinha commented on PR #5331:


8 months ago
#26

@felixarntz @mukeshpanchal27

I made the change and didn't find any issues.

#27 @flixos90
8 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 56756:

Media: Prevent PHP notice in get_avatar().

Follow up fix to [56690].

Props pereirinha, mukesh27, spacedmonkey.
Fixes #58892.

#29 @flixos90
7 months ago

  • Keywords has-dev-note added; needs-dev-note removed
Note: See TracTickets for help on using tickets.