Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion src/Compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public function __construct() {
add_filter( 'sgo_javascript_combine_excluded_external_paths', [ $this, 'exclude_plausible_js' ] );
}

// W3 Total Cache
if ( defined( 'W3TC_VERSION' ) ) {
add_filter( 'w3tc_minify_js_script_tags', [ $this, 'unset_plausible_js' ] );
}

// WPML
if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
add_filter( 'rest_url', [ $this, 'wpml_compatibility' ], 10, 1 );
Expand Down Expand Up @@ -110,6 +115,26 @@ public function exclude_plausible_js( $excluded_js ) {
return $excluded_js;
}

/**
* Remove Plausible.js (or the local file, when proxy is enabled) of the list of JS files to minify.
*
* @filter w3tc_minify_js_script_tags
* @since 2.4.0
*
* @param $script_tags
*
* @return array
* @throws Exception
*/
public function unset_plausible_js( $script_tags ) {
return array_filter(
$script_tags,
function ( $tag ) {
return str_contains( $tag, Helpers::get_js_url( true ) ) === false;
}
);
}

/**
* Dear WP Rocket/SG Optimizer/Etc., don't minify/combine/delay our external JS, please.
*
Expand All @@ -128,7 +153,11 @@ public function exclude_plausible_js_by_relative_url( $excluded_js ) {
}

/**
* Dear WP Rocket/SG Optimizer/Etc. don't minify/combine/delay our API endpoint, please.
* Some optimization plugins (WP Rocket) replace the JS src URL with their own URL, before being able to exclude it.
* So, when the proxy is enabled, exclusion fails. That's why we exclude again by proxy endpoint.
*
* @filter rocket_delay_js_exclusions
* @since 2.4.0
*
* @param $excluded_js
*
Expand Down