wp-rocket icon indicating copy to clipboard operation
wp-rocket copied to clipboard

Cache recreated on each page load when WebP Caching is enabled

Open piotrbak opened this issue 4 years ago • 5 comments

Describe the bug When other HTML minification solutions are enabled, it's possible that WebP cached files will be recreated on each visit.

To Reproduce Steps to reproduce the behavior:

  1. Install WP Rocket on a site where expected WebP images are present
  2. Add HTML minification plugin, the one used for tests is this: https://wordpress.org/plugins/clearfy/
  3. Enable the plugin and enable Optimize HTML Code here: /wp-admin/admin.php?page=minify_and_combine-wbcr_clearfy
  4. Enable WP Rocket's WebP Caching feature
  5. Visit the homepage and refresh it a couple of times to see that it's getting recreated

Additional context The problem is related to the fact, that HTML minificator is removing our WebP comment: https://github.com/wp-media/wp-rocket/blob/e40b824350a165cf52f2285a681d5b6796ed5555/inc/classes/Buffer/class-cache.php#L284

Slack discussion: https://wp-media.slack.com/archives/CBJ2KQ0MU/p1583276391193300?thread_ts=1582790459.097100&cid=CBJ2KQ0MU

piotrbak avatar Mar 04 '20 22:03 piotrbak

This needs some product discussion before going into grooming. @arunbasillal @GeekPress

How should we approach this kind of bugs created by other optimization plugins?

  • Display a warning for this plugin when active?
  • Change the way we handle our has webp/no webp detection in the buffer? (major change for us)
  • Change the whole buffer process? (major change for us)
  • Contact the plugin author to ask them to not strip this HTML comment when performing their HTML minification?

remyperona avatar Mar 10 '20 15:03 remyperona

This one is a plugin incompatibility. Basically the HTML minification in Clearfy isn't compatible with WP Rocket.

So let's treat it just like that and show the incompatibility notice when:

  • HTML minification in Clearfy is active
  • WP Rocket's WebP Caching is active

We can simply advise users to use HTML minification in WP Rocket in the incompatibility notice. Our standard notice will show the deactivate plugin link as well. We can think of what to do with it.

About other options @Tabrisrp mentioned:

  • The second and third options are too expensive for us.
  • The fourth one is feasible. But this exception is a very specific one. Did we check to see if the plugin already has filters in the HTML minification exclusion list? If so that would be the easiest for everyone.

arunbasillal avatar Mar 12 '20 12:03 arunbasillal

The conflict with Clearfy is "just" with their Optimize HTML option. It's hard to display a notice to advise our users to totally deactivate Clearfy. If we do a notice I vote to deactivate only their Optimize HTML option.

@Tabrisrp Could you tell me which HTML comment they have to not strip? I'm going to contact them.

GeekPress avatar Mar 13 '20 14:03 GeekPress

The following comments need to be preserved: <!-- Rocket has webp --> <!-- Rocket no webp -->

remyperona avatar Mar 13 '20 14:03 remyperona

Another scenario: 1- Enable AMP transitional mode 2- Enable the WebP compatibility option and save 3- Access the AMP page i.e https://rocketlabsqa.ovh/football-soccer/?amp 4- Check source after refresh multiple times => no timestamp is added there

Mai-Saad avatar Mar 29 '22 08:03 Mai-Saad