2026-10-08 GLOBAL
This commit is contained in:
parent
0b220e0031
commit
9fc2e1822f
@ -3675,9 +3675,20 @@ add_action('wp_head', function () {
|
||||
if ($thumb) {
|
||||
$src = wp_get_attachment_image_src($thumb, 'large');
|
||||
$set = wp_get_attachment_image_srcset($thumb, 'large');
|
||||
$webp = function_exists('dekart_format_srcset') ? dekart_format_srcset($thumb, 'webp') : '';
|
||||
$sizes = '(max-width: 860px) 92vw, 588px';
|
||||
if ($src) {
|
||||
echo '<link rel="preload" as="image" href="' . esc_url($src[0]) . '"'
|
||||
. ( $set ? ' imagesrcset="' . esc_attr($set) . '" imagesizes="(max-width: 860px) 92vw, 600px"' : '' )
|
||||
// предзагружаем тот же оптимизированный файл, что выберет <picture>
|
||||
$href = $src[0];
|
||||
$type = '';
|
||||
if ($webp) {
|
||||
$first = preg_split('/\s+/', explode(',', $webp)[0]);
|
||||
$href = $first[0];
|
||||
$type = ' type="image/webp"';
|
||||
$set = $webp;
|
||||
}
|
||||
echo '<link rel="preload" as="image"' . $type . ' href="' . esc_url($href) . '"'
|
||||
. ( $set ? ' imagesrcset="' . esc_attr($set) . '" imagesizes="' . esc_attr($sizes) . '"' : '' )
|
||||
. ' fetchpriority="high">' . "\n";
|
||||
}
|
||||
}
|
||||
@ -4678,6 +4689,33 @@ function dekart_output_gtm_body()
|
||||
}
|
||||
}
|
||||
|
||||
// Виджет чата/кнопок — только по взаимодействию (без idle-таймера)
|
||||
function dekart_widget_loader_script($blocks): string
|
||||
{
|
||||
$blocks = array_values(array_filter((array) $blocks, static function ($b) {
|
||||
return '' !== trim((string) $b);
|
||||
}));
|
||||
if (! $blocks) {
|
||||
return '';
|
||||
}
|
||||
$json = wp_json_encode($blocks, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_TAG);
|
||||
return '<script>(function(){var B=' . $json . ';var done=false;function inject(){if(done){return;}done=true;try{var seen={};B.join(" ").replace(/https?:\/\/([^\/"\s]+)/g,function(m,h){h=h.toLowerCase();if(seen[h]){return m;}seen[h]=1;var l=document.createElement("link");l.rel="preconnect";l.href="https://"+h;l.crossOrigin="";(document.head||document.documentElement).appendChild(l);return m;});}catch(e){}B.forEach(function(html){var t=document.createElement("template");t.innerHTML=html;Array.prototype.slice.call(t.content.childNodes).forEach(function(n){var node;if(n.nodeName==="SCRIPT"){node=document.createElement("script");for(var i=0;i<n.attributes.length;i++){node.setAttribute(n.attributes[i].name,n.attributes[i].value);}node.text=n.textContent||"";}else{node=n.cloneNode(true);}(document.head||document.documentElement).appendChild(node);});});}var ev=["scroll","click","keydown","mousemove","touchstart","pointerdown"];function go(){ev.forEach(function(e){window.removeEventListener(e,go);});inject();}ev.forEach(function(e){window.addEventListener(e,go,{passive:true,once:true});});})();</script>';
|
||||
}
|
||||
|
||||
// WP Additional CSS — не блокирует рендер (media=print → onload all)
|
||||
remove_action('wp_head', 'wp_custom_css_cb', 101);
|
||||
add_action('wp_head', function () {
|
||||
if (! function_exists('wp_get_custom_css')) {
|
||||
return;
|
||||
}
|
||||
$css = (string) wp_get_custom_css();
|
||||
if ('' === trim($css)) {
|
||||
return;
|
||||
}
|
||||
echo '<style id="wp-custom-css" media="print" onload="this.media=\'all\'">' . $css . '</style>' . "\n";
|
||||
echo '<noscript><style>' . $css . '</style></noscript>' . "\n";
|
||||
}, 101);
|
||||
|
||||
add_action('wp_footer', 'dekart_output_counters_footer', 100);
|
||||
function dekart_output_counters_footer()
|
||||
{
|
||||
@ -4686,8 +4724,7 @@ function dekart_output_counters_footer()
|
||||
}
|
||||
$footer = stripslashes(get_option('dekart_counter_footer', ''));
|
||||
if (trim((string) $footer)) {
|
||||
|
||||
echo dekart_deferred_loader_script(array( $footer ), 3500) . "\n";
|
||||
echo dekart_widget_loader_script(array( $footer )) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user