From b47741358f444fcab72bae3853f5d74b46b8479a Mon Sep 17 00:00:00 2001 From: Timotei Date: Thu, 4 Apr 2024 00:56:45 +0300 Subject: [PATCH 1/2] Disable QS for non cached pages Fix a bug when QS remove is turn on and on non-cached pages this not need to happen. See trello: remove query string still takes place in no-cache page --- src/optimize.cls.php | 54 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/optimize.cls.php b/src/optimize.cls.php index d680cefad..82fc2b5ad 100644 --- a/src/optimize.cls.php +++ b/src/optimize.cls.php @@ -133,6 +133,12 @@ function ($con, $file_type) { * @since 1.7.1 */ $this->_dns_prefetch_init(); + + /** + * Prefetch resources + * @since 6.3 + */ + $this->_prefetch_init(); /** * Preconnect @@ -206,7 +212,12 @@ public function rm_cache_folder($subsite_id = false) */ public function remove_query_strings($src) { - if (strpos($src, '_litespeed_rm_qs=0') || strpos($src, '/recaptcha')) { + $is_not_cached = false; + if(defined('DONOTCACHEPAGE')){ + $is_not_cached = DONOTCACHEPAGE; + } + + if ($is_not_cached===true || (strpos($src, '_litespeed_rm_qs=0') || strpos($src, '/recaptcha'))) { return $src; } @@ -669,6 +680,19 @@ private function _dns_prefetch_init() } } + /** + * Prefetch resources + * + * @since 6.3 + * @access private + */ + private function _prefetch_init() + { + if (function_exists('wp_resource_hints')) { + add_filter('wp_resource_hints', array($this, 'prefetch_filter'), 11, 2); + } + } + /** * Preconnect init * @@ -718,6 +742,34 @@ public function dns_prefetch_output() } } + /** + * Prefetch hook for WP + * + * @since 6.3 + * @access public + */ + public function prefetch_filter($urls, $relation_type) + { + if ($relation_type === 'dns-prefetch') { + return $urls; + } + + $is_not_cached = false; + if(defined('DONOTCACHEPAGE')){ + $is_not_cached = DONOTCACHEPAGE; + } + + if($is_not_cached===false && $this->conf(self::O_OPTM_QS_RM)){ + foreach ($urls as &$v) { + if (!empty($v['href'])) { + $v['href'] = $this->remove_query_strings($v['href']); + } + } + } + + return $urls; + } + /** * Preconnect * From 37d978fc964c0271d5522941d4fd4966138f8fae Mon Sep 17 00:00:00 2001 From: Timotei Date: Thu, 4 Apr 2024 21:55:23 +0300 Subject: [PATCH 2/2] Changes --- src/optimize.cls.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/optimize.cls.php b/src/optimize.cls.php index 82fc2b5ad..ac05218ab 100644 --- a/src/optimize.cls.php +++ b/src/optimize.cls.php @@ -217,7 +217,7 @@ public function remove_query_strings($src) $is_not_cached = DONOTCACHEPAGE; } - if ($is_not_cached===true || (strpos($src, '_litespeed_rm_qs=0') || strpos($src, '/recaptcha'))) { + if ($is_not_cached || (strpos($src, '_litespeed_rm_qs=0') || strpos($src, '/recaptcha'))) { return $src; }