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

Automatically exclude `data-noptimize` and `data-no-optimize` and `data-cfasync="false"` from optimizations

Open DahmaniAdame opened this issue 2 years ago • 3 comments

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

  • [x] Made sure you’re on the latest version 3.13.1
  • [x] Used the search feature to ensure that the bug hasn’t been reported before

Describe the bug Some plugins/themes/services will use a hint about assets that they don't want to see optimized further by setting to true the following attributes data-noptimize and data-no-optimize, data-no-minify or setting to false the following attributes data-cfasync and data-optimized as they know it might cause issues.

As a preemptive measure, we can respect that hint and automatically exclude them from modification, JavaScript defer and delay.

Note that for data-noptimize and data-no-optimize we should only exclude them if they are set to true by either having the attribute being added with no value or having 1 or true as a value.

For data-optimized and data-cfasync, the check should be for 0 or false values.

One example is Antispam-bee. They add a script with data-noptimize, and if delayed, it will prompt an error on the Accessibility audit on Lighthouse.

image

Another example is Mediavine using it on their script that we are automatically excluding from combination and Delay JavaScript Execution:

<script type="text/javascript" async="async" data-noptimize="1" data-cfasync="false" src="//scripts.mediavine.com/tags/YourSiteHere.js"></script>

Behavior matrix:

  • data-noptimize and data-no-optimize set to true or 1 = exclude from all optimizations.
  • data-optimized set to false or 0 = exclude from all optimizations.
  • data-no-minify set to true or 1 = exclude from minification.
  • data-cfasync set to false or 0 = exclude from js defer and js delay as a precaution since Cloudflare Rocket Loader that the attribute is meant to control has a similar behavior.

To Reproduce Sited example of use cases.

Expected behavior We should respect hints about exclusion from optimizations as a preemptive measure.

Screenshots N/A

Additional context Ticket involving the Antispan Bee - https://secure.helpscout.net/conversation/2229183958/417412

Backlog Grooming (for WP Media dev team use only)

  • [ ] Reproduce the problem
  • [ ] Identify the root cause
  • [ ] Scope a solution
  • [ ] Estimate the effort

DahmaniAdame avatar May 05 '23 08:05 DahmaniAdame

@DahmaniAdame to confirm, it's about the scripts and we should exclude scripts from:

  • Delay JS
  • Defer JS
  • Minification and Combination

piotrbak avatar May 05 '23 08:05 piotrbak

@piotrbak yes. That should only be applied to scripts for now. We can take that opportunity to introduce our own skip attributes to help 3rd party devs to skip scripts at will without requiring to use a filter for that. I discussed with Mostafa the possibility of introducing a skip attribute handling on RUCSS as well to help with cases like this one - https://github.com/wp-media/wp-rocket/issues/5283 We could use data-wpr-skip as all-in-one skip attribute, and data-wpr-skip- + feature abbreviation for feature-specific exclusions. Like data-wpr-skip-dje for excluding a script from Delay JavaScript Execution, and so on.

DahmaniAdame avatar May 05 '23 20:05 DahmaniAdame

Developers from borlabs are also requesting we support data-noptimize and data-no-optimize to exclude JS files from our optimizations https://secure.helpscout.net/conversation/2414653718/453464?folderId=2683093

alfonso100 avatar Nov 22 '23 14:11 alfonso100