Null Is Not Zero: Building a JavaScript SEO Audit That Admits Its Limits
We moved a server-side SEO engine into a Chrome extension. Measuring the page was the easy half. Saying what we could not measure was the hard half. We had been running an on-page analysis engine on our own servers for years. You give it a URL, it fetches the page, it reports. Ordinary. Then we moved that engine into the browser, because a server cannot reach localhost , a staging box, an…
The authors transitioned a server-side SEO engine into a Chrome extension. Measuring the page was straightforward, but identifying what they couldn't measure proved challenging. Traditionally, the on-page analysis engine ran on their own servers, receiving a URL, fetching the page, and generating a report. However, the browser extension required a different approach.
Moving the analysis engine into the browser wasn't difficult; the real challenge lay in handling a category of issues that couldn't be measured on the server. In a live tab, certain measurements were sometimes unavailable, and the honest answer was not a number. This post discusses the decisions made and the code that implements them, with the rule "Null Is Not Zero" at its core.
Every derivation in the engine returns a "number | null." A "0" signifies that the measurement was taken and the result is zero. On the other hand, "null" denotes that the measurement couldn't be taken. The browser failed to support the entry type, the document originated from another origin, or the size fields were zeroed out. A "0" printed where a "null" should be is a fabricated number.
It is worse than an empty cell because there's no way for the reader to distinguish between a real measurement and an arbitrary number. Therefore, the two never converge: the derivation maintains them as separate entities, and the user interface renders them differently.
This straightforward concept is surprisingly easy to violate. The next section highlights the most common way to do so. The PerformanceObserver fails silently, so it's essential to check first before observing. When calling observe() with an entry type that the browser doesn't support, it doesn't throw an error or provide a warning.
Instead, it quietly does nothing, and the corresponding handler is never called. This outcome is identical to the scenario where a measured zero is returned, violating the "Null Is Not Zero" rule. To mitigate this issue, the authors advise asking before observing and recording the refusal. By checking if the PerformanceObserver is supported and including the unsupported metrics in a separate list, developers can prevent the misleading presentation of fabricated numbers.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.