short-pixel-optimizer / enable-media-replace

Enable Media Replace WordPress plugin
GNU General Public License v2.0
20 stars 27 forks source link

Media Replacement failing when Cloudflare and ShortPixel are enabled #71

Closed tpolischuk closed 1 year ago

tpolischuk commented 3 years ago

I am running into a consistent problem where images can't be swapped when using a CDN (Cloudflare) and Shortpixel. Basically what I believe is happening is the new image is uploaded, and when ShortPixel attempts to optimize the newly uploaded image, it's grabbing the old version from the CDN, effectively making it so the image never swaps.

I wonder if ShortPixel could be configured to optimize the image using an ever-changing url parameter, essentially guaranteeing that ShortPixel won't grab the old version from the CDN?

bschuiling commented 3 years ago

Hi,

Please try to add this constant to your wp-config.php : define("SHORTPIXEL_EXPERIMENTAL_SECURICACHE", true);

This will add a timestamp to the optimize URLs.

tpolischuk commented 3 years ago

Wow cool let me try that! I just want to double check that's the correct spelling of the constant?

SHORTPIXEL_EXPERIMENTAL_SECURICACHE

Just checking because the product is Sucuri but I want to make sure I'm using the version referenced by the plugin.

pdobrescu commented 2 years ago

hey @tpolischuk, apologies for not getting back to you on this sooner. Yes, the spelling is right and you can see this constant defined (but commented by default) in ShortPixel Image Optimizer here (for the current latest version 4.22.6):

https://github.com/short-pixel-optimizer/shortpixel-image-optimiser/blob/master/wp-shortpixel.php#L80

please let us know if this solves the issue.

pdobrescu commented 1 year ago

That cache buster mechanism has been added to the ShortPixel Image Optimizer plugin by default starting with version 5.0.0, therefore this issue should not happen anymore. I'll go ahead and close it, feel free to reopen it if you still have issues @tpolischuk