Skip to content

Declare concepts as defined terms, and stop analytics blocking the paint - #25

Open
msmfa wants to merge 2 commits into
masterfrom
term-schema-and-deferred-analytics
Open

Declare concepts as defined terms, and stop analytics blocking the paint#25
msmfa wants to merge 2 commits into
masterfrom
term-schema-and-deferred-analytics

Conversation

@msmfa

@msmfa msmfa commented Sep 11, 2026

Copy link
Copy Markdown
Owner

Two separate changes, one commit each.

Declare each concept a defined term in a glossary set

Every page's structured data described only where the page sat (WebSite, WebPage, BreadcrumbList). Nothing described what it held.

Each concept page now also declares:

  • DefinedTerm with the short definition, sameAs pointing at the MDN page for the same term, and inDefinedTermSet pointing at the glossary
  • TechArticle wrapping the prose, with proficiencyLevel from the existing Fundamentals/Advanced split and dateModified from the same content commit the sitemap uses

The home page declares a DefinedTermSet listing all 35 terms, so the glossary and its terms reference each other in both directions.

Costs about 1.9 KB per page uncompressed.

Hold the analytics bundles back until the page has painted

With consent already granted, gtag.js and PostHog's array.js were injected as soon as the module ran. Both are async so neither blocked rendering, but 248 KiB of parse work competed with the main thread during first paint. Lighthouse measured element render delay at 1.1s inside a mobile LCP of 3.8s, with 120 KiB of the two bundles never executing.

The shims, the gtag('config') call and PostHog's _i stub queue still run synchronously. Only the two script() injections move behind requestIdleCallback after load, with a 1500ms deadline and a timer fallback for Safari below 16.4. The $pageview is still queued when it happens, and both vendors replay what was buffered.

Tradeoff worth knowing: a visitor who leaves inside that window now goes uncounted.

Verification

  • 76 tests pass, up from 74
  • New: bundles are absent before paint but gtag, the PostHog stub and the queued page view all exist; PostHog replays the $pageview on loaded
  • New: a browser with no requestIdleCallback still loads both via the timer
  • Two existing consent tests got stricter: zero scripts immediately after the click with the page view already queued, two after paint
  • All 36 pages parse as valid JSON-LD, 143 unique @ids, 247 references, zero dangling
  • schema.org validator returns 0 errors

The graph on every page described only where a page sat: WebSite, WebPage
and a BreadcrumbList. Nothing said what a page held, so a concept page and
any other page looked like the same kind of thing to a crawler.

Each concept now adds a DefinedTerm carrying the short definition, pointing
at the MDN page for the same term through sameAs, and claiming membership of
a DefinedTermSet that the home page declares over all thirty-five concepts.
A TechArticle wraps the prose around it, with the proficiency level taken
from the existing Fundamentals and Advanced split and the modified date from
the same content commit the sitemap already uses.

This matters more for assistants answering "what is a closure in JavaScript"
than for blue links: a page that names itself the definition of a term is far
easier to identify as the source than one that only names itself a page.
Consent already granted meant gtag.js and PostHog's array.js were injected
the moment the module ran. Both are async, so neither blocked rendering, but
a quarter of a megabyte of parse work competed with the main thread while it
was still painting. Lighthouse put element render delay at 1.1s inside a
mobile LCP of 3.8s, and 120 KiB of the two bundles never executed at all.

Nothing either vendor does matters before the page is visible, and both are
built to be started late: gtag buffers through dataLayer and PostHog through
its _i stub queue. So the shims, the config call and the stub still run
synchronously, and only the two script injections move behind an idle
callback after load. The page view is still queued at the moment it happens
rather than when the bundles land.

The idle deadline is 1500ms: long enough to clear the paint, short enough
that a quick bounce is still recorded. Safari below 16.4 has no
requestIdleCallback and falls back to a timer, which by then is also clear
of the paint.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant