Skip to content
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
58 changes: 56 additions & 2 deletions src/optimize.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,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 @@ -203,10 +209,17 @@ public function rm_cache_folder( $subsite_id = false ) {
* Remove QS
*
* @since 1.3
* @since 7.3 - added no cache condition
* @access public
*/
public function remove_query_strings( $src ) {
if (strpos($src, '_litespeed_rm_qs=0') || strpos($src, '/recaptcha')) {
public function remove_query_strings($src)
{
$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 +682,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 @@ -715,6 +741,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