imagify-plugin icon indicating copy to clipboard operation
imagify-plugin copied to clipboard

Update callback priority on template_redirect for picture display

Open remyperona opened this issue 6 months ago • 7 comments

Context Related to https://github.com/wp-media/wp-rocket/issues/6786

WP Rocket Lazyload exclusion is not working correctly when excluded pattern is part of a picture element created by the picture rewriting feature of Imagify.

Expected beavhior Lazyload exclusion should work as expected

Additional information So I believe I found what was happening with the next-gen issue. we have 2 callbacks on template_redirect:

  • Imagify callback on priority -1000
  • WP Rocket callback on priority 2

So we should expect imagify to be finished first, and WP Rocket after. BUT, both callbacks have an ob_start() call, and when multiple are called, they become nested until the buffering stops:

  • Imagify opens buffer first
  • then WP Rocket, nested inside

When output buffering ends (on shutdown action of WP), lower level content is passed to upper, so the order becomes WP Rocket optimizations first, then Imagify second, and HTML is output. While callback priority is as expected, the output buffering works in the opposite order.

To verify, I tested by changing the priority of Imagify callback to 10, reverting both orders, and it works as expected, the picture element is applied first in the HTML, and then lazyload exclusion works as needed.

remyperona avatar Aug 07 '24 18:08 remyperona