Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qs remove disable on noncache #701

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
54 changes: 53 additions & 1 deletion src/optimize.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 || (strpos($src, '_litespeed_rm_qs=0') || strpos($src, '/recaptcha'))) {
return $src;
}

Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*
Expand Down
Loading