@@ -43,6 +43,11 @@ public function __construct() {
43
43
add_filter ( 'sgo_javascript_combine_excluded_external_paths ' , [ $ this , 'exclude_plausible_js ' ] );
44
44
}
45
45
46
+ // W3 Total Cache
47
+ if ( defined ( 'W3TC_VERSION ' ) ) {
48
+ add_filter ( 'w3tc_minify_js_script_tags ' , [ $ this , 'unset_plausible_js ' ] );
49
+ }
50
+
46
51
// WPML
47
52
if ( defined ( 'ICL_SITEPRESS_VERSION ' ) ) {
48
53
add_filter ( 'rest_url ' , [ $ this , 'wpml_compatibility ' ], 10 , 1 );
@@ -110,6 +115,26 @@ public function exclude_plausible_js( $excluded_js ) {
110
115
return $ excluded_js ;
111
116
}
112
117
118
+ /**
119
+ * Remove Plausible.js (or the local file, when proxy is enabled) of the list of JS files to minify.
120
+ *
121
+ * @filter w3tc_minify_js_script_tags
122
+ * @since 2.4.0
123
+ *
124
+ * @param $script_tags
125
+ *
126
+ * @return array
127
+ * @throws Exception
128
+ */
129
+ public function unset_plausible_js ( $ script_tags ) {
130
+ return array_filter (
131
+ $ script_tags ,
132
+ function ( $ tag ) {
133
+ return str_contains ( $ tag , Helpers::get_js_url ( true ) ) === false ;
134
+ }
135
+ );
136
+ }
137
+
113
138
/**
114
139
* Dear WP Rocket/SG Optimizer/Etc., don't minify/combine/delay our external JS, please.
115
140
*
@@ -128,7 +153,11 @@ public function exclude_plausible_js_by_relative_url( $excluded_js ) {
128
153
}
129
154
130
155
/**
131
- * Dear WP Rocket/SG Optimizer/Etc. don't minify/combine/delay our API endpoint, please.
156
+ * Some optimization plugins (WP Rocket) replace the JS src URL with their own URL, before being able to exclude it.
157
+ * So, when the proxy is enabled, exclusion fails. That's why we exclude again by proxy endpoint.
158
+ *
159
+ * @filter rocket_delay_js_exclusions
160
+ * @since 2.4.0
132
161
*
133
162
* @param $excluded_js
134
163
*
0 commit comments