Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/litespee.../src
File: optimize.cls.php
} else {
[500] Fix | Delete
// Put header content to dummy css position
[501] Fix | Delete
if (false !== preg_match(self::DUMMY_CSS_REGEX, $this->content)) {
[502] Fix | Delete
self::debug('Put optm data to dummy css location');
[503] Fix | Delete
$this->content = preg_replace( self::DUMMY_CSS_REGEX, $this->html_head, $this->content );
[504] Fix | Delete
}
[505] Fix | Delete
// Fallback: try to be after charset
[506] Fix | Delete
elseif (strpos($this->content, '<meta charset') !== false) {
[507] Fix | Delete
self::debug('Put optm data to be after <meta charset>');
[508] Fix | Delete
$this->content = preg_replace('#<meta charset([^>]*)>#isU', '<meta charset$1>' . $this->html_head, $this->content, 1);
[509] Fix | Delete
} else {
[510] Fix | Delete
self::debug('Put optm data to be after <head>');
[511] Fix | Delete
$this->content = preg_replace('#<head([^>]*)>#isU', '<head$1>' . $this->html_head, $this->content, 1);
[512] Fix | Delete
}
[513] Fix | Delete
}
[514] Fix | Delete
}
[515] Fix | Delete
[516] Fix | Delete
// Replace html foot part
[517] Fix | Delete
$this->html_foot = apply_filters('litespeed_optm_html_foot', $this->html_foot);
[518] Fix | Delete
if ($this->html_foot) {
[519] Fix | Delete
$this->content = str_replace('</body>', $this->html_foot . '</body>', $this->content);
[520] Fix | Delete
}
[521] Fix | Delete
[522] Fix | Delete
// Drop noscript if enabled
[523] Fix | Delete
if ($this->conf(self::O_OPTM_NOSCRIPT_RM)) {
[524] Fix | Delete
// $this->content = preg_replace( '#<noscript>.*</noscript>#isU', '', $this->content );
[525] Fix | Delete
}
[526] Fix | Delete
[527] Fix | Delete
// Inline font-face optimize
[528] Fix | Delete
$this->content = $this->__optimizer->optm_font_face( $this->content );
[529] Fix | Delete
[530] Fix | Delete
// HTML minify
[531] Fix | Delete
if (defined('LITESPEED_GUEST_OPTM') || $this->conf(self::O_OPTM_HTML_MIN)) {
[532] Fix | Delete
$this->content = $this->__optimizer->html_min($this->content);
[533] Fix | Delete
}
[534] Fix | Delete
}
[535] Fix | Delete
[536] Fix | Delete
/**
[537] Fix | Delete
* Build a full JS tag
[538] Fix | Delete
*
[539] Fix | Delete
* @since 4.0
[540] Fix | Delete
*/
[541] Fix | Delete
private function _build_js_tag( $src ) {
[542] Fix | Delete
if ($this->cfg_js_defer === 2 || Utility::str_hit_array($src, $this->cfg_js_delay_inc)) {
[543] Fix | Delete
return '<script data-optimized="1" type="litespeed/javascript" data-src="' . Str::trim_quotes($src) . '"></script>';
[544] Fix | Delete
}
[545] Fix | Delete
[546] Fix | Delete
if ($this->cfg_js_defer) {
[547] Fix | Delete
return '<script data-optimized="1" src="' . Str::trim_quotes($src) . '" defer></script>';
[548] Fix | Delete
}
[549] Fix | Delete
[550] Fix | Delete
return '<script data-optimized="1" src="' . Str::trim_quotes($src) . '"></script>';
[551] Fix | Delete
}
[552] Fix | Delete
[553] Fix | Delete
/**
[554] Fix | Delete
* Build a full inline JS snippet
[555] Fix | Delete
*
[556] Fix | Delete
* @since 4.0
[557] Fix | Delete
*/
[558] Fix | Delete
private function _build_js_inline( $script, $minified = false ) {
[559] Fix | Delete
if ($this->cfg_js_defer) {
[560] Fix | Delete
$deferred = $this->_js_inline_defer($script, false, $minified);
[561] Fix | Delete
if ($deferred) {
[562] Fix | Delete
return $deferred;
[563] Fix | Delete
}
[564] Fix | Delete
}
[565] Fix | Delete
[566] Fix | Delete
return '<script>' . $script . '</script>';
[567] Fix | Delete
}
[568] Fix | Delete
[569] Fix | Delete
/**
[570] Fix | Delete
* Load JS delay lib
[571] Fix | Delete
*
[572] Fix | Delete
* @since 4.0
[573] Fix | Delete
*/
[574] Fix | Delete
private function _maybe_js_delay() {
[575] Fix | Delete
if ($this->cfg_js_defer !== 2 && !$this->cfg_js_delay_inc) {
[576] Fix | Delete
return;
[577] Fix | Delete
}
[578] Fix | Delete
[579] Fix | Delete
if (!defined('LITESPEED_JS_DELAY_LIB_LOADED')) {
[580] Fix | Delete
define('LITESPEED_JS_DELAY_LIB_LOADED', true);
[581] Fix | Delete
$this->html_foot .= '<script>' . File::read(LSCWP_DIR . self::LIB_FILE_JS_DELAY) . '</script>';
[582] Fix | Delete
}
[583] Fix | Delete
}
[584] Fix | Delete
[585] Fix | Delete
/**
[586] Fix | Delete
* Google font async
[587] Fix | Delete
*
[588] Fix | Delete
* @since 2.7.3
[589] Fix | Delete
* @access private
[590] Fix | Delete
*/
[591] Fix | Delete
private function _async_ggfonts() {
[592] Fix | Delete
if (!$this->cfg_ggfonts_async || !$this->_ggfonts_urls) {
[593] Fix | Delete
return;
[594] Fix | Delete
}
[595] Fix | Delete
[596] Fix | Delete
self::debug2('google fonts async found: ', $this->_ggfonts_urls);
[597] Fix | Delete
[598] Fix | Delete
$this->html_head_early .= '<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin />';
[599] Fix | Delete
[600] Fix | Delete
/**
[601] Fix | Delete
* Append fonts
[602] Fix | Delete
*
[603] Fix | Delete
* Could be multiple fonts
[604] Fix | Delete
*
[605] Fix | Delete
* <link rel='stylesheet' href='//fonts.googleapis.com/css?family=Open+Sans%3A400%2C600%2C700%2C800%2C300&#038;ver=4.9.8' type='text/css' media='all' />
[606] Fix | Delete
* <link rel='stylesheet' href='//fonts.googleapis.com/css?family=PT+Sans%3A400%2C700%7CPT+Sans+Narrow%3A400%7CMontserrat%3A600&#038;subset=latin&#038;ver=4.9.8' type='text/css' media='all' />
[607] Fix | Delete
* -> family: PT Sans:400,700|PT Sans Narrow:400|Montserrat:600
[608] Fix | Delete
* <link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,300,300italic,400italic,600,700,900&#038;subset=latin%2Clatin-ext' />
[609] Fix | Delete
*/
[610] Fix | Delete
$script = 'WebFontConfig={google:{families:[';
[611] Fix | Delete
[612] Fix | Delete
$families = array();
[613] Fix | Delete
foreach ($this->_ggfonts_urls as $v) {
[614] Fix | Delete
$qs = wp_specialchars_decode($v);
[615] Fix | Delete
$qs = urldecode($qs);
[616] Fix | Delete
$qs = parse_url($qs, PHP_URL_QUERY);
[617] Fix | Delete
parse_str($qs, $qs);
[618] Fix | Delete
[619] Fix | Delete
if (empty($qs['family'])) {
[620] Fix | Delete
self::debug('ERR ggfonts failed to find family: ' . $v);
[621] Fix | Delete
continue;
[622] Fix | Delete
}
[623] Fix | Delete
[624] Fix | Delete
$subset = empty($qs['subset']) ? '' : ':' . $qs['subset'];
[625] Fix | Delete
[626] Fix | Delete
foreach (array_filter(explode('|', $qs['family'])) as $v2) {
[627] Fix | Delete
$families[] = Str::trim_quotes($v2 . $subset);
[628] Fix | Delete
}
[629] Fix | Delete
}
[630] Fix | Delete
[631] Fix | Delete
$script .= '"' . implode('","', $families) . ($this->_conf_css_font_display ? '&display=swap' : '') . '"';
[632] Fix | Delete
[633] Fix | Delete
$script .= ']}};';
[634] Fix | Delete
[635] Fix | Delete
// if webfontloader lib was loaded before WebFontConfig variable, call WebFont.load
[636] Fix | Delete
$script .= 'if ( typeof WebFont === "object" && typeof WebFont.load === "function" ) { WebFont.load( WebFontConfig ); }';
[637] Fix | Delete
[638] Fix | Delete
$html = $this->_build_js_inline($script);
[639] Fix | Delete
[640] Fix | Delete
// https://cdnjs.cloudflare.com/ajax/libs/webfont/1.6.28/webfontloader.js
[641] Fix | Delete
$webfont_lib_url = LSWCP_PLUGIN_URL . self::LIB_FILE_WEBFONTLOADER;
[642] Fix | Delete
[643] Fix | Delete
// default async, if js defer set use defer
[644] Fix | Delete
$html .= $this->_build_js_tag($webfont_lib_url);
[645] Fix | Delete
[646] Fix | Delete
// Put this in the very beginning for preconnect
[647] Fix | Delete
$this->html_head = $html . $this->html_head;
[648] Fix | Delete
}
[649] Fix | Delete
[650] Fix | Delete
/**
[651] Fix | Delete
* Font optm
[652] Fix | Delete
*
[653] Fix | Delete
* @since 3.0
[654] Fix | Delete
* @access private
[655] Fix | Delete
*/
[656] Fix | Delete
private function _font_optm() {
[657] Fix | Delete
if (!$this->_conf_css_font_display || !$this->_ggfonts_urls) {
[658] Fix | Delete
return;
[659] Fix | Delete
}
[660] Fix | Delete
[661] Fix | Delete
self::debug2('google fonts optm ', $this->_ggfonts_urls);
[662] Fix | Delete
[663] Fix | Delete
foreach ($this->_ggfonts_urls as $v) {
[664] Fix | Delete
if (strpos($v, 'display=')) {
[665] Fix | Delete
continue;
[666] Fix | Delete
}
[667] Fix | Delete
$this->html_head = str_replace($v, $v . '&#038;display=swap', $this->html_head);
[668] Fix | Delete
$this->html_foot = str_replace($v, $v . '&#038;display=swap', $this->html_foot);
[669] Fix | Delete
$this->content = str_replace($v, $v . '&#038;display=swap', $this->content);
[670] Fix | Delete
}
[671] Fix | Delete
}
[672] Fix | Delete
[673] Fix | Delete
/**
[674] Fix | Delete
* Prefetch DNS
[675] Fix | Delete
*
[676] Fix | Delete
* @since 1.7.1 DNS prefetch
[677] Fix | Delete
* @since 5.6.1 DNS preconnect
[678] Fix | Delete
* @access private
[679] Fix | Delete
*/
[680] Fix | Delete
private function _dns_optm_init() {
[681] Fix | Delete
// Widely enable link DNS prefetch
[682] Fix | Delete
if (defined('LITESPEED_GUEST_OPTM') || $this->conf(self::O_OPTM_DNS_PREFETCH_CTRL)) {
[683] Fix | Delete
@header('X-DNS-Prefetch-Control: on');
[684] Fix | Delete
}
[685] Fix | Delete
[686] Fix | Delete
$this->dns_prefetch = $this->conf(self::O_OPTM_DNS_PREFETCH);
[687] Fix | Delete
$this->dns_preconnect = $this->conf(self::O_OPTM_DNS_PRECONNECT);
[688] Fix | Delete
if (!$this->dns_prefetch && !$this->dns_preconnect) {
[689] Fix | Delete
return;
[690] Fix | Delete
}
[691] Fix | Delete
[692] Fix | Delete
if (function_exists('wp_resource_hints')) {
[693] Fix | Delete
add_filter('wp_resource_hints', array( $this, 'dns_optm_filter' ), 10, 2);
[694] Fix | Delete
} else {
[695] Fix | Delete
add_action('litespeed_optm', array( $this, 'dns_optm_output' ));
[696] Fix | Delete
}
[697] Fix | Delete
}
[698] Fix | Delete
[699] Fix | Delete
/**
[700] Fix | Delete
* DNS optm hook for WP
[701] Fix | Delete
*
[702] Fix | Delete
* @since 1.7.1
[703] Fix | Delete
* @access public
[704] Fix | Delete
*/
[705] Fix | Delete
public function dns_optm_filter( $urls, $relation_type ) {
[706] Fix | Delete
if ('dns-prefetch' === $relation_type) {
[707] Fix | Delete
foreach ($this->dns_prefetch as $v) {
[708] Fix | Delete
if ($v) {
[709] Fix | Delete
$urls[] = $v;
[710] Fix | Delete
}
[711] Fix | Delete
}
[712] Fix | Delete
}
[713] Fix | Delete
if ('preconnect' === $relation_type) {
[714] Fix | Delete
foreach ($this->dns_preconnect as $v) {
[715] Fix | Delete
if ($v) {
[716] Fix | Delete
$urls[] = $v;
[717] Fix | Delete
}
[718] Fix | Delete
}
[719] Fix | Delete
}
[720] Fix | Delete
[721] Fix | Delete
return $urls;
[722] Fix | Delete
}
[723] Fix | Delete
[724] Fix | Delete
/**
[725] Fix | Delete
* DNS optm output directly
[726] Fix | Delete
*
[727] Fix | Delete
* @since 1.7.1 DNS prefetch
[728] Fix | Delete
* @since 5.6.1 DNS preconnect
[729] Fix | Delete
* @access public
[730] Fix | Delete
*/
[731] Fix | Delete
public function dns_optm_output() {
[732] Fix | Delete
foreach ($this->dns_prefetch as $v) {
[733] Fix | Delete
if ($v) {
[734] Fix | Delete
$this->html_head_early .= '<link rel="dns-prefetch" href="' . Str::trim_quotes($v) . '" />';
[735] Fix | Delete
}
[736] Fix | Delete
}
[737] Fix | Delete
foreach ($this->dns_preconnect as $v) {
[738] Fix | Delete
if ($v) {
[739] Fix | Delete
$this->html_head_early .= '<link rel="preconnect" href="' . Str::trim_quotes($v) . '" crossorigin />';
[740] Fix | Delete
}
[741] Fix | Delete
}
[742] Fix | Delete
}
[743] Fix | Delete
[744] Fix | Delete
/**
[745] Fix | Delete
* Run minify with src queue list
[746] Fix | Delete
*
[747] Fix | Delete
* @since 1.2.2
[748] Fix | Delete
* @access private
[749] Fix | Delete
*/
[750] Fix | Delete
private function _src_queue_handler( $src_list, $html_list, $file_type = 'css' ) {
[751] Fix | Delete
$html_list_ori = $html_list;
[752] Fix | Delete
[753] Fix | Delete
$can_webp = $this->cls('Media')->webp_support();
[754] Fix | Delete
[755] Fix | Delete
$tag = $file_type == 'css' ? 'link' : 'script';
[756] Fix | Delete
foreach ($src_list as $key => $src_info) {
[757] Fix | Delete
// Minify inline CSS/JS
[758] Fix | Delete
if (!empty($src_info['inl'])) {
[759] Fix | Delete
if ($file_type == 'css') {
[760] Fix | Delete
$code = Optimizer::minify_css($src_info['src']);
[761] Fix | Delete
$can_webp && ($code = $this->cls('Media')->replace_background_webp($code));
[762] Fix | Delete
$snippet = str_replace($src_info['src'], $code, $html_list[$key]);
[763] Fix | Delete
} else {
[764] Fix | Delete
// Inline defer JS
[765] Fix | Delete
if ($this->cfg_js_defer) {
[766] Fix | Delete
$attrs = !empty($src_info['attrs']) ? $src_info['attrs'] : '';
[767] Fix | Delete
$snippet = $this->_js_inline_defer($src_info['src'], $attrs) ?: $html_list[$key];
[768] Fix | Delete
} else {
[769] Fix | Delete
$code = Optimizer::minify_js($src_info['src']);
[770] Fix | Delete
$snippet = str_replace($src_info['src'], $code, $html_list[$key]);
[771] Fix | Delete
}
[772] Fix | Delete
}
[773] Fix | Delete
}
[774] Fix | Delete
// CSS/JS files
[775] Fix | Delete
else {
[776] Fix | Delete
$url = $this->_build_single_hash_url($src_info['src'], $file_type);
[777] Fix | Delete
if ($url) {
[778] Fix | Delete
$snippet = str_replace($src_info['src'], $url, $html_list[$key]);
[779] Fix | Delete
}
[780] Fix | Delete
[781] Fix | Delete
// Handle css async load
[782] Fix | Delete
if ($file_type == 'css' && $this->cfg_css_async) {
[783] Fix | Delete
$snippet = $this->_async_css($snippet);
[784] Fix | Delete
}
[785] Fix | Delete
[786] Fix | Delete
// Handle js defer
[787] Fix | Delete
if ($file_type === 'js' && $this->cfg_js_defer) {
[788] Fix | Delete
$snippet = $this->_js_defer($snippet, $src_info['src']) ?: $snippet;
[789] Fix | Delete
}
[790] Fix | Delete
}
[791] Fix | Delete
[792] Fix | Delete
$snippet = str_replace("<$tag ", '<' . $tag . ' data-optimized="1" ', $snippet);
[793] Fix | Delete
$html_list[$key] = $snippet;
[794] Fix | Delete
}
[795] Fix | Delete
[796] Fix | Delete
$this->content = str_replace($html_list_ori, $html_list, $this->content);
[797] Fix | Delete
}
[798] Fix | Delete
[799] Fix | Delete
/**
[800] Fix | Delete
* Build a single URL mapped filename (This will not save in DB)
[801] Fix | Delete
*
[802] Fix | Delete
* @since 4.0
[803] Fix | Delete
*/
[804] Fix | Delete
private function _build_single_hash_url( $src, $file_type = 'css' ) {
[805] Fix | Delete
$content = $this->__optimizer->load_file($src, $file_type);
[806] Fix | Delete
[807] Fix | Delete
$is_min = $this->__optimizer->is_min($src);
[808] Fix | Delete
[809] Fix | Delete
$content = $this->__optimizer->optm_snippet($content, $file_type, !$is_min, $src);
[810] Fix | Delete
[811] Fix | Delete
$filepath_prefix = $this->_build_filepath_prefix($file_type);
[812] Fix | Delete
[813] Fix | Delete
// Save to file
[814] Fix | Delete
$filename = $filepath_prefix . md5($this->remove_query_strings($src)) . '.' . $file_type;
[815] Fix | Delete
$static_file = LITESPEED_STATIC_DIR . $filename;
[816] Fix | Delete
File::save($static_file, $content, true);
[817] Fix | Delete
[818] Fix | Delete
// QS is required as $src may contains version info
[819] Fix | Delete
$qs_hash = substr(md5($src), -5);
[820] Fix | Delete
return LITESPEED_STATIC_URL . "$filename?ver=$qs_hash";
[821] Fix | Delete
}
[822] Fix | Delete
[823] Fix | Delete
/**
[824] Fix | Delete
* Generate full URL path with hash for a list of src
[825] Fix | Delete
*
[826] Fix | Delete
* @since 1.2.2
[827] Fix | Delete
* @access private
[828] Fix | Delete
*/
[829] Fix | Delete
private function _build_hash_url( $src_list, $file_type = 'css' ) {
[830] Fix | Delete
// $url_sensitive = $this->conf( self::O_OPTM_CSS_UNIQUE ) && $file_type == 'css'; // If need to keep unique CSS per URI
[831] Fix | Delete
[832] Fix | Delete
// Replace preserved ESI (before generating hash)
[833] Fix | Delete
if ($file_type == 'js') {
[834] Fix | Delete
foreach ($src_list as $k => $v) {
[835] Fix | Delete
if (empty($v['inl'])) {
[836] Fix | Delete
continue;
[837] Fix | Delete
}
[838] Fix | Delete
$src_list[$k]['src'] = $this->_preserve_esi($v['src']);
[839] Fix | Delete
}
[840] Fix | Delete
}
[841] Fix | Delete
[842] Fix | Delete
$minify = $file_type === 'css' ? $this->cfg_css_min : $this->cfg_js_min;
[843] Fix | Delete
$filename_info = $this->__optimizer->serve($this->_request_url, $file_type, $minify, $src_list);
[844] Fix | Delete
[845] Fix | Delete
if (!$filename_info) {
[846] Fix | Delete
return false; // Failed to generate
[847] Fix | Delete
}
[848] Fix | Delete
[849] Fix | Delete
list($filename, $type) = $filename_info;
[850] Fix | Delete
[851] Fix | Delete
// Add cache tag in case later file deleted to avoid lscache served stale non-existed files @since 4.4.1
[852] Fix | Delete
Tag::add(Tag::TYPE_MIN . '.' . $filename);
[853] Fix | Delete
[854] Fix | Delete
$qs_hash = substr(md5(self::get_option(self::ITEM_TIMESTAMP_PURGE_CSS)), -5);
[855] Fix | Delete
// As filename is already related to filecon md5, no need QS anymore
[856] Fix | Delete
$filepath_prefix = $this->_build_filepath_prefix($type);
[857] Fix | Delete
return LITESPEED_STATIC_URL . $filepath_prefix . $filename . '?ver=' . $qs_hash;
[858] Fix | Delete
}
[859] Fix | Delete
[860] Fix | Delete
/**
[861] Fix | Delete
* Parse js src
[862] Fix | Delete
*
[863] Fix | Delete
* @since 1.2.2
[864] Fix | Delete
* @access private
[865] Fix | Delete
*/
[866] Fix | Delete
private function _parse_js() {
[867] Fix | Delete
$excludes = apply_filters('litespeed_optimize_js_excludes', $this->conf(self::O_OPTM_JS_EXC));
[868] Fix | Delete
[869] Fix | Delete
$combine_ext_inl = $this->conf(self::O_OPTM_JS_COMB_EXT_INL);
[870] Fix | Delete
if (!apply_filters('litespeed_optm_js_comb_ext_inl', true)) {
[871] Fix | Delete
self::debug2('js_comb_ext_inl bypassed via litespeed_optm_js_comb_ext_inl filter');
[872] Fix | Delete
$combine_ext_inl = false;
[873] Fix | Delete
}
[874] Fix | Delete
[875] Fix | Delete
$src_list = array();
[876] Fix | Delete
$html_list = array();
[877] Fix | Delete
[878] Fix | Delete
// V7 added: (?:\r\n?|\n?) to fix replacement leaving empty new line
[879] Fix | Delete
$content = preg_replace('#<!--.*-->(?:\r\n?|\n?)#sU', '', $this->content);
[880] Fix | Delete
preg_match_all('#<script([^>]*)>(.*)</script>(?:\r\n?|\n?)#isU', $content, $matches, PREG_SET_ORDER);
[881] Fix | Delete
foreach ($matches as $match) {
[882] Fix | Delete
$attrs = empty($match[1]) ? array() : Utility::parse_attr($match[1]);
[883] Fix | Delete
[884] Fix | Delete
if (isset($attrs['data-optimized'])) {
[885] Fix | Delete
continue;
[886] Fix | Delete
}
[887] Fix | Delete
if (!empty($attrs['data-no-optimize'])) {
[888] Fix | Delete
continue;
[889] Fix | Delete
}
[890] Fix | Delete
if (!empty($attrs['data-cfasync']) && $attrs['data-cfasync'] === 'false') {
[891] Fix | Delete
continue;
[892] Fix | Delete
}
[893] Fix | Delete
if (!empty($attrs['type']) && $attrs['type'] != 'text/javascript') {
[894] Fix | Delete
continue;
[895] Fix | Delete
}
[896] Fix | Delete
[897] Fix | Delete
// to avoid multiple replacement
[898] Fix | Delete
if (in_array($match[0], $html_list)) {
[899] Fix | Delete
continue;
[900] Fix | Delete
}
[901] Fix | Delete
[902] Fix | Delete
$this_src_arr = array();
[903] Fix | Delete
// JS files
[904] Fix | Delete
if (!empty($attrs['src'])) {
[905] Fix | Delete
// Exclude check
[906] Fix | Delete
$js_excluded = Utility::str_hit_array($attrs['src'], $excludes);
[907] Fix | Delete
$is_internal = Utility::is_internal_file($attrs['src']);
[908] Fix | Delete
$is_file = substr($attrs['src'], 0, 5) != 'data:';
[909] Fix | Delete
$ext_excluded = !$combine_ext_inl && !$is_internal;
[910] Fix | Delete
if ($js_excluded || $ext_excluded || !$is_file) {
[911] Fix | Delete
// Maybe defer
[912] Fix | Delete
if ($this->cfg_js_defer) {
[913] Fix | Delete
$deferred = $this->_js_defer($match[0], $attrs['src']);
[914] Fix | Delete
if ($deferred) {
[915] Fix | Delete
$this->content = str_replace($match[0], $deferred, $this->content);
[916] Fix | Delete
}
[917] Fix | Delete
}
[918] Fix | Delete
[919] Fix | Delete
self::debug2('_parse_js bypassed due to ' . ($js_excluded ? 'js files excluded [hit] ' . $js_excluded : 'external js'));
[920] Fix | Delete
continue;
[921] Fix | Delete
}
[922] Fix | Delete
[923] Fix | Delete
if (strpos($attrs['src'], '/localres/') !== false) {
[924] Fix | Delete
continue;
[925] Fix | Delete
}
[926] Fix | Delete
[927] Fix | Delete
if (strpos($attrs['src'], 'instant_click') !== false) {
[928] Fix | Delete
continue;
[929] Fix | Delete
}
[930] Fix | Delete
[931] Fix | Delete
$this_src_arr['src'] = $attrs['src'];
[932] Fix | Delete
}
[933] Fix | Delete
// Inline JS
[934] Fix | Delete
elseif (!empty($match[2])) {
[935] Fix | Delete
// self::debug( '🌹🌹🌹 ' . $match[2] . '🌹' );
[936] Fix | Delete
// Exclude check
[937] Fix | Delete
$js_excluded = Utility::str_hit_array($match[2], $excludes);
[938] Fix | Delete
if ($js_excluded || !$combine_ext_inl) {
[939] Fix | Delete
// Maybe defer
[940] Fix | Delete
if ($this->cfg_js_defer) {
[941] Fix | Delete
$deferred = $this->_js_inline_defer($match[2], $match[1]);
[942] Fix | Delete
if ($deferred) {
[943] Fix | Delete
$this->content = str_replace($match[0], $deferred, $this->content);
[944] Fix | Delete
}
[945] Fix | Delete
}
[946] Fix | Delete
self::debug2('_parse_js bypassed due to ' . ($js_excluded ? 'js excluded [hit] ' . $js_excluded : 'inline js'));
[947] Fix | Delete
continue;
[948] Fix | Delete
}
[949] Fix | Delete
[950] Fix | Delete
$this_src_arr['inl'] = true;
[951] Fix | Delete
$this_src_arr['src'] = $match[2];
[952] Fix | Delete
if ($match[1]) {
[953] Fix | Delete
$this_src_arr['attrs'] = $match[1];
[954] Fix | Delete
}
[955] Fix | Delete
} else {
[956] Fix | Delete
// Compatibility to those who changed src to data-src already
[957] Fix | Delete
self::debug2('No JS src or inline JS content');
[958] Fix | Delete
continue;
[959] Fix | Delete
}
[960] Fix | Delete
[961] Fix | Delete
$src_list[] = $this_src_arr;
[962] Fix | Delete
$html_list[] = $match[0];
[963] Fix | Delete
}
[964] Fix | Delete
[965] Fix | Delete
return array( $src_list, $html_list );
[966] Fix | Delete
}
[967] Fix | Delete
[968] Fix | Delete
/**
[969] Fix | Delete
* Inline JS defer
[970] Fix | Delete
*
[971] Fix | Delete
* @since 3.0
[972] Fix | Delete
* @access private
[973] Fix | Delete
*/
[974] Fix | Delete
private function _js_inline_defer( $con, $attrs = false, $minified = false ) {
[975] Fix | Delete
if (strpos($attrs, 'data-no-defer') !== false) {
[976] Fix | Delete
self::debug2('bypass: attr api data-no-defer');
[977] Fix | Delete
return false;
[978] Fix | Delete
}
[979] Fix | Delete
[980] Fix | Delete
$hit = Utility::str_hit_array($con, $this->cfg_js_defer_exc);
[981] Fix | Delete
if ($hit) {
[982] Fix | Delete
self::debug2('inline js defer excluded [setting] ' . $hit);
[983] Fix | Delete
return false;
[984] Fix | Delete
}
[985] Fix | Delete
[986] Fix | Delete
$con = trim($con);
[987] Fix | Delete
// Minify JS first
[988] Fix | Delete
if (!$minified) {
[989] Fix | Delete
// && $this->cfg_js_defer !== 2
[990] Fix | Delete
$con = Optimizer::minify_js($con);
[991] Fix | Delete
}
[992] Fix | Delete
[993] Fix | Delete
if (!$con) {
[994] Fix | Delete
return false;
[995] Fix | Delete
}
[996] Fix | Delete
[997] Fix | Delete
// Check if the content contains ESI nonce or not
[998] Fix | Delete
$con = $this->_preserve_esi($con);
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function