diff --git a/includes/class-compatibility.php b/includes/class-compatibility.php index 3b3a9e7..cfa59e6 100644 --- a/includes/class-compatibility.php +++ b/includes/class-compatibility.php @@ -31,10 +31,19 @@ private function init() { new CAOS_Compatibility_Autoptimize(); } + /** + * Always run Cloudflare compatibility, because it doesn't do any harm. + */ + new CAOS_Compatibility_Cloudflare(); + if ( defined( 'LSCWP_V' ) ) { new CAOS_Compatibility_Litespeed(); } + if ( defined( 'WPFC_MAIN_PATH' ) ) { + new CAOS_Compatibility_WpFastestCache(); + } + if ( defined( 'WP_ROCKET_VERSION' ) ) { new CAOS_Compatibility_WpRocket(); } diff --git a/includes/compatibility/class-cloudflare.php b/includes/compatibility/class-cloudflare.php new file mode 100644 index 0000000..c789b1a --- /dev/null +++ b/includes/compatibility/class-cloudflare.php @@ -0,0 +1,43 @@ +init(); + } + + /** + * Action and filter hooks. + * + * @return void + */ + private function init() { + add_filter( 'caos_script_custom_attributes', [ $this, 'exclude_from_cloudflare' ] ); + } + + /** + * Add data-no-optimize="1" attribute to script if LiteSpeed Cache is enabled. + * + * @param $attributes + * + * @return string + */ + public function exclude_from_cloudflare( $attributes ) { + return 'data-cfasync="false" ' . $attributes; + } +} \ No newline at end of file diff --git a/includes/compatibility/class-wp-fastest-cache.php b/includes/compatibility/class-wp-fastest-cache.php new file mode 100644 index 0000000..503a73b --- /dev/null +++ b/includes/compatibility/class-wp-fastest-cache.php @@ -0,0 +1,43 @@ +init(); + } + + /** + * Action and filter hooks. + * + * @return void + */ + private function init() { + add_filter( 'caos_script_custom_attributes', [ $this, 'exclude_from_wpfc' ] ); + } + + /** + * Add data-no-optimize="1" attribute to script if LiteSpeed Cache is enabled. + * + * @param $attributes + * + * @return string + */ + public function exclude_from_wpfc( $attributes ) { + return 'data-wpfc-render="false" ' . $attributes; + } +} \ No newline at end of file