wp-media / wp-rocket

Performance optimization plugin for WordPress
https://wp-rocket.me
GNU General Public License v2.0
701 stars 218 forks source link

OCI: when using a CDN that's a subdomain cdn.site.com, imagesrcset urls inside preload tag are not replaced to use the CDN cname #6958

Open alfonso100 opened 1 month ago

alfonso100 commented 1 month ago

Before submitting an issue please check that you’ve completed the following steps: yes - Made sure you’re on the latest version yes - Used the search feature to ensure that the bug hasn’t been reported before

Describe the bug When the CDN is a subdomain of the site url, for example cdn.wphangar.com and we inject the OCI markup, the CDN replacement won’t be applied to the imagesrcset images, only to the href image:

CDN setting: cdn.wphangar.com

LCP entry in the DB: {"type":"img-srcset","src":"https://wphangar.com/wp-content/uploads/2022/12/e5ec5320-c85f-3612-a79f-68079e82f341-1024x683.jpg","srcset":"https://wphangar.com/wp-content/uploads/2022/12/e5ec5320-c85f-3612-a79f-68079e82f341-1024x683.jpg 1024w, https://wphangar.com/wp-content/uploads/2022/12/e5ec5320-c85f-3612-a79f-68079e82f341-600x400.jpg 600w, https://wphangar.com/wp-content/uploads/2022/12/e5ec5320-c85f-3612-a79f-68079e82f341-300x200.jpg 300w, https://wphangar.com/wp-content/uploads/2022/12/e5ec5320-c85f-3612-a79f-68079e82f341-768x512.jpg 768w, https://wphangar.com/wp-content/uploads/2022/12/e5ec5320-c85f-3612-a79f-68079e82f341.jpg 1152w","sizes":"(max-width: 1024px) 100vw, 1024px"}

resulting markup: <link rel="preload" data-rocket-preload as="image" href="https://cdn.wphangar.com/wp-content/uploads/2022/12/e5ec5320-c85f-3612-a79f-68079e82f341-1024x683.jpg" imagesrcset="https://wphangar.com/wp-content/uploads/2022/12/e5ec5320-c85f-3612-a79f-68079e82f341-1024x683.jpg 1024w, https://wphangar.com/wp-content/uploads/2022/12/e5ec5320-c85f-3612-a79f-68079e82f341-600x400.jpg 600w, https://wphangar.com/wp-content/uploads/2022/12/e5ec5320-c85f-3612-a79f-68079e82f341-300x200.jpg 300w, https://wphangar.com/wp-content/uploads/2022/12/e5ec5320-c85f-3612-a79f-68079e82f341-768x512.jpg 768w, https://wphangar.com/wp-content/uploads/2022/12/e5ec5320-c85f-3612-a79f-68079e82f341.jpg 1152w" imagesizes="(max-width: 1024px) 100vw, 1024px" fetchpriority="high">

To Reproduce Steps to reproduce the behavior:

  1. manually add the LCP entry in the db for a URL
  2. Set the CDN to use cdn.siteurl.com
  3. see the imagesrcset URLs not replaced in the preload tag

Expected behavior we should replace all the URLs when the CDN is used

Additional context

Slack thread: https://wp-media.slack.com/archives/C072P5EU5DF/p1725644143674919

Tickets: https://secure.helpscout.net/conversation/2700575552/511133/ https://secure.helpscout.net/conversation/2698303805/510752/

Acceptance Criteria (for WP Media team use only) Clear instructions for developers, to be added before the grooming

girlie commented 1 month ago

This is apparently not limited to CDNs that are subdomains of the origin domain, as I've got another case where the SRCSET is also not being written to the CDN, but the domain is third-party hosted:

TICKET: https://secure.helpscout.net/conversation/2708093350/512378/ SITE: https://www.ciotalknetwork.com/ CDN: https://eweajxggxf5.exactdn.com/