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

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

Open DahmaniAdame opened 1 year ago

DahmaniAdame commented 1 year ago

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

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:

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)

piotrbak commented 1 year ago

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

DahmaniAdame commented 1 year ago

@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 wpr-skip as all-in-one skip attribute, and wpr-skip- + feature abbreviation for feature-specific exclusions. Like wpr-skip-dje for excluding a script from Delay JavaScript Execution, and so on.

alfonso100 commented 11 months ago

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