Repository navigation
Description
Description
On a normal page visit, the page profiler sends every background selector with an empty object, for example "b":{"[style*=\"background-image:url(\"]":{}}. This happens even when a background element is above the fold and its URL has been found. The stored profile ends up with "bg":{"<selector>":[]} for every device. Optimole therefore never learns which background images are above the fold, and the lazy-load CSS can only exempt the LCP background.
Cause
In assets/js/modules/main.js, the IntersectionObserver is created with the first selectorMap instance. Shortly after, selectorMap is replaced with a new Map:
// main.js:110-111
let selectorMap = new Map();
const observer = optmlImageDetector.createIntersectionObserver(aboveTheFoldImages, selectorMap);
...
// main.js:135
selectorMap = backgroundResult.selectorMap;The observer callback (image-detector.js:100) checks selectorMap.has(baseSelector) against the original Map, which is always empty. Above-the-fold background elements are therefore never recorded. Meanwhile _processBackgroundSelectors (main.js:174) builds b from the new Map, which has the selector keys but no entries. With ?optml_debug=1, the log never prints Element with selector "…" is above the fold for background elements.
Expected: each matched selector lists the above-the-fold elements and their URLs, e.g. {"[style*=\"background-image:url(\"]":{"#content > … > div.wp-block-cover__image-background…":["https://…/qa-hero-bg.jpg"]}}.
Verification of the cause
I changed one line in the served script so it fills the existing Map instead of replacing it (backgroundResult.selectorMap.forEach((v, k) => selectorMap.set(k, v))). With that change:
- The payload contained the selector and its URL.
- The server stored them for mobile and desktop.
- The lazy-load CSS on the page added a
:not(...)exclusion for each above-the-fold background element, not only the LCP one.
I tested this on a page with two background groups side by side.
Impact
On pages with a single hero, nothing visible changes, because the hero is also the LCP element and is exempted and preloaded anyway. On pages with several background images above the fold, the ones that aren't the LCP element are still lazy-loaded. They can appear late and cost LCP/CLS points, which is what the profiler is meant to prevent.
Possible fix
Fill the existing Map, or pass the Map from processBackgroundSelectors to the observer, instead of reassigning selectorMap.
A related timing detail: extractBackgroundImageUrls runs right after processBackgroundSelectors (main.js:139), before the 300/600 ms wait. A background that gets optml-bg-lazyloaded during the wait would be sent with null URLs.
Not related to #1204 / #1214: it appears on both the released 4.2.17 build and the #1214 build. Found while testing #1204.
Step-by-step reproduction instructions
- Optimole 4.2.17, connected, with Lazy load and background lazy load on.
- Create a page whose first block has a background image in an inline style. For example, a Cover block with "Fixed background" on, or a Group block with a background image.
- In a private window (logged out), open the page with
?optml_debug=1appended. Keep the console open. - In the console, look at
Sending background selectors:. Or look at the payload of the request to/wp-json/optml/v1/optimizations. - Load the page in a mobile-width window too, so both devices are profiled. Then open it with
?optml_debug=trueand read the<!-- plugin=optimole-wp measurement#… -->comment after</html>.
Result: b contains each matched selector with {}, and the stored profile shows "bg":{"…":[]} for both devices. Only the LCP background (lcp.bgUrls) is stored.
Screenshots, screen recording, code snippet or Help Scout ticket
Code links:
https://github.com/Codeinwp/optimole-wp/blob/v4.2.17/assets/js/modules/main.js#L110-L135
https://github.com/Codeinwp/optimole-wp/blob/v4.2.17/assets/js/modules/image-detector.js#L82-L104
Environment info
Optimole 4.2.17 (same code on master), WordPress + Neve, PHP 8.5, Chromium desktop 1440px / mobile 390px
Is the issue you are reporting a regression
No
Activity
girishpanchal30 commentedon Nov 16, 2026
@rodica-andronache I have fixed it with PR #1240
milicavs commentedon Nov 17, 2026
🧪 QA steps and test links
Optimole's page profiler never records which background images sit above the fold. Every background selector is sent as an empty
{}, so on pages with several above-the-fold backgrounds, the ones that aren't the LCP element stay lazy-loaded and can appear late. Nothing changes visually on the page itself; the proof is in the profiler's debug output.{}for both background selectors, so neither background was recorded1ad036aIn the links:
?optml_debug=1. Open the browser console (F12) before the page loads, or reload once it is open.measurementcomment.debug.log.Reproduce on Optimole 4.2.20:
<div>s, each withstyle="background-image:url(...);height:400px"(above the fold).?optml_debug=1and the console open.Sending background selectors:and look forElement with selector "…" is above the foldlines.{}, and no "is above the fold" line appears for the backgrounds.Edge cases
?optml_debug=true: themeasurementcomment after</html>lists both elements underbgfor both devices.Fix: #1240 (open)
girishpanchal30 commentedon Nov 17, 2026
@pirate-bot test
girishpanchal30 commentedon Nov 18, 2026
@pirate-bot test
pirate-bot commentedon Nov 18, 2026
QA agent — 🟢 Passing checks · Above-the-fold backgrounds are now stored and exempted from lazy loading.
The test site used a stand-in Optimole connection and local image delivery. Desktop and mobile profiles stored both background URLs, and the resulting CSS exempted both images while keeping the lower image lazy-loaded. The base build reproduced the empty profiles, while the candidate also passed the delayed-load and limit checks.
Worth a human look
Checks (7 passed)
Full report, evidence and session trail