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

CDN is not replacing URLs using escape characters #4956

Closed DahmaniAdame closed 4 months ago

DahmaniAdame commented 2 years ago

Before submitting an issue please check that you’ve completed the following steps:

Describe the bug When the CDN feature is enabled, we are not replacing domains using escape characters.

Example:

https:\/\/domain.ext\/wp-content\/uploads\/2022\/03\/18.jpg

This will cause the browsers to fetch some resources from the origin server, which might impact performance and scores.

Escape characters are used on tags attributes and JavaScript codes.

We could look for that kind of URLs using the following REGEX:

'/("|\'|;| )https:\\\\\/\\\\\/(domain.ext)\\\\\/wp-content\\\\\/(.*?)\.(jpg|jpeg|png|webp|js|css|svg|avif)/'

And proceed with the replacement.

The 4 //// are needed to match / on the code. That is 5 ///// total.

To Reproduce Steps to reproduce the behavior:

  1. Use resources with an escape character
  2. Enable the CDN feature
  3. See that resources using an escape character are not replaced

Expected behavior The CDN feature should replace all resources with the CNAME.

Screenshots N/A

Additional context Ticket - https://secure.helpscout.net/conversation/1853815839/338286

Backlog Grooming (for WP Media dev team use only)

webtrainingwheels commented 1 year ago

@DahmaniAdame Could you share the helper plugin here or on the ticket? I think I have a similar case and would like to test it

DahmaniAdame commented 1 year ago

@webtrainingwheels, the helper was to manipulate the buffer, the same as Alfonso provided on Slack.

webtrainingwheels commented 1 year ago

This will cause the browsers to fetch some resources from the origin server, which might impact performance and scores.

In this case: https://secure.helpscout.net/conversation/2239860817/419437?folderId=377611 This problem actually breaks a feature on the customer's site - product images don't swap as they should when a different color is selected.

If anyone else needs to solve this problem, you can use the below helper plugin. You need to edit line 23 with the relevant domains. wp-rocket-manipulate-buffer.php.zip

webtrainingwheels commented 1 year ago

I think this is a duplicate of https://github.com/wp-media/wp-rocket/issues/2353 ? Should they be merged?

piotrbak commented 4 months ago

We did not have enough feedback from customers related to this issue. We might reopen this in the future.