CoreBoost v3.3.6
🐛 Fixed - LCP Foreground Injection (cb-lcp) Not Firing
Root Cause
inject_lcp_foreground_image() used a subcapture group for attribute extraction:
([^>]*\bclass=["\'][^"\']*\bcb-lcp\b[^"\']*["\'][^>]*). PCRE backtracking on the trailing
[^>]* could cause attributes such as data-coreboost-deferred-youtube or the inline style
to fall outside $matches[2], resulting in the function finding no image URL and silently
returning the original tag — so cb-lcp-img never appeared in the source.
A second cascading failure: even when smart_youtube_blocking was ON, the image URL was not being
found because Elementor applies the fallback as an inline CSS background on the wrapper element
(not in data-settings) and that path was never checked.
A third latent bug: start_output_buffer() only ran the output buffer when smart_youtube_blocking
or a script/CSS defer feature was active. If only enable_lcp_foreground_injection was on,
the buffer never started and injection never ran.
Changes
inject_lcp_foreground_image()fully rewritten. Outer regex simplified to
/<[a-z][a-z0-9]*\s[^>]*\bcb-lcp\b[^>]*>/i— no subcapture groups. All four attribute
extractions run directly on$matches[0](the full opening tag string), eliminating the
PCRE backtracking failure mode entirely.- 3-level image URL cascade:
data-settingsJSON →background_video_fallback.urlthenbackground_image.url
(present when smart_youtube_blocking is OFF).data-coreboost-deferred-youtubeJSON →fallback.url/fallback(string)
(present when smart_youtube_blocking has stripped data-settings).- Inline
styleattribute — per Elementor's architecture, the video fallback is
rendered asstyle="background: url('...') 50% 50%; background-size: cover;"on the
wrapper element by theGroup_Control_BackgroundCSS selector. This level is always
present in the rendered HTML and was previously never read.
<link rel="preload">now injected directly frominject_lcp_foreground_image(). After
thepreg_replace_callbackpass, the first resolved image URL is injected as a
<link rel="preload" fetchpriority="high">before</head>. This makes the head preload
independent ofHero_Optimizer::preload_video_hero()and thepreload_methodsetting —
so it fires correctly regardless of which hero detection method is configured.start_output_buffer()gate extended to include
!empty($this->options['enable_lcp_foreground_injection']). Previously the output buffer
only ran when a script/CSS defer or smart_youtube_blocking feature was also active; disabling
those features would silently prevent LCP injection from running at all.
Files Modified
includes/public/class-resource-remover.php—inject_lcp_foreground_image()full rewrite;start_output_buffer()buffer-start condition