CSS and JavaScript

For developersVersion 1.0.0Last updated:

OptionDefaultWhat it does
Minify CSSOnCopy without comments or extra whitespace. It respects strings, url(), calc() and selectors like a :hover. It keeps /*! licencia */ comments.
Inline critical CSSOn (up to 50 KB per page)If the CSS of the packages the page needs (already optimized and, with “CSS per section”, only that of its sections) weighs less than the limit in total, it is printed in the <head> inside <style id="bos-<slug>-inline"> in the same place where its <link> would go: same order, after the theme’s global styles and before the Global design. The page doesn’t wait for any BuilderOS stylesheet to paint. Relative url()s are converted to absolute. BuilderOS’s own CSS (animations, forms, site; a few KB) is always inline when the page uses it, apart from the limit. Package stylesheets of 2 KB or less are always embedded, even if the total doesn’t fit (a blocking request for a 63-byte sheet isn’t worth it; it goes in its place, in the same order).
CSS per sectionOnOn pages with a canvas, each page receives only the package rules its sections use, plus the global ones, in the original order. That way it usually fits inline and stops blocking. See “CSS per section, in detail”.
Minify JS (conservative)OffRemoves comments and indentation keeping line breaks, strings, templates and regular expressions. If something can’t be parsed safely, the original is served. .min.js files aren’t touched.
Sections below the fold: content-visibilityOffThe browser doesn’t lay out or paint sections far from the screen until they get close (content-visibility: auto) and reserves each one’s real measured height (“Measure heights” button). It lowers mobile TBT on long pages. See “content-visibility, in detail”.
JS with deferOnThe package’s scripts load with defer (except modules, which already are). It is compatible with BuilderOS.ready, which works before and after the DOM loads. If another script depends on one from the package and can’t be deferred, WordPress loads it as before.
Inline runtimeOnEmbeds the BuilderOS runtime (1.5 KB) in the HTML: one fewer blocking request in the <head>.

If the CSS weighs more than the limit, everything loads as usual, with <link>. Loading it without blocking (preload + onload) would make the page show for an instant without styles (FOUC), because without a browser you can’t know which rules are the above-the-fold ones. It’s a deliberate decision: embedding only part wouldn’t help either, because with a single blocking sheet the page already waits. You can raise the limit up to 100 KB.

Inline CSS comes from the active version’s folder, so it changes with each version just as the <link>‘s ?ver= used to.

The default limit went up from 25 to 50 KB: with “CSS per section” what gets embedded is only the page’s CSS (about 10–12 KB compressed), and removing the blocking request counts for more in PageSpeed than those bytes in the HTML. Sites that had the previous limit (25 KB) saved move to 50 KB on their own when updating; if you change it by hand, it is respected.

Why BuilderOS’s own CSS doesn’t use a one-year cache: the plugin folder is replaced on every update and its version only appears in the URL’s ?ver=, which some optimizers remove (“Remove query strings”); the browser could keep an old copy. Since it weighs a few KB, it is embedded in the HTML.

Why the limit stays at 50 KB (measured): the home page of a package with 68 KB of CSS (6 sheets) with the limit at 100 KB embeds everything and brings first paint forward (FCP 1.7 s → 1.1 s), but that early paint leaves a long style and layout task for the entire page inside the TBT window: mobile TBT went from ~280 ms to ~720 ms (score 93 → 82), with and without content-visibility. With 50 KB they are linked, and sheets of 2 KB or less are embedded. If your package is smaller, the limit doesn’t matter; if you raise it, measure with PageSpeed before and after.

content-visibility, in detail:

  • What is printed. On the first element of each “below the fold” section (those that aren’t the header, main section or visible on load; the footer is included): data-bos-cv="<bloque>~<huella>" and style="--bos-cv-m:<px>;--bos-cv-d:<px>" (content height on mobile and on desktop, from 901 px), plus a <style id="bos-cv-css"> of about 600 bytes with content-visibility: auto and contain-intrinsic-size: auto <altura>. The auto makes the browser remember the real height once it has painted.
  • Measured heights. BuilderOS → Performance → Settings → Code → “Section heights” → Measure heights: the administrator’s browser opens each page (each language’s home page and every published post with sections, in all languages, up to 500; its own list, the performance report still has its 30) in an invisible frame of 412 × 800 and of 1350 × 900 px with content-visibility turned off, and saves each section’s height (without padding or border, because contain-intrinsic-size is the content box’s size). The key includes the block, its data and the language. An unmeasured section (edited or new, or an A/B test variant): the average of those of the same type or, if there is none, 700 px. It is saved in batches of 10 pages (if the tab is closed, what was measured remains; the status says “Measuring heights X of N…”) in the builder_os_perf_heights option (no autoload, up to 3000 sections, under 300 KB) and clears the page caches. After installing a package (Builder_OS_Perf_Postinstall) it happens on its own: the result screen measures the pages the package created or updated, in all languages, plus the home pages (not if content_visibility is off), and then clears the cache (“Measuring heights 10 of N… → Clearing cache… → Done”). Every install (panel, WP-CLI, REST, MCP) also schedules ONE WP-Cron event (builder_os_postinstall, after 5 minutes) that the browser cancels when it finishes; if it doesn’t, cron clears the cache and notifies the bell how many pages are still unmeasured (measuring needs a browser), with a link to Performance. Cache providers: BuilderOS, Cloudflare (API and official plugin, to whose cloudflare_purge_everything_actions filter BuilderOS adds its action), Varnish, LiteSpeed (plugin and server, including Hostinger’s), WP Rocket, W3TC, WP Super Cache, SiteGround, WP Fastest Cache, Cache Enabler, Breeze, WP-Optimize, Nginx Helper and WP Engine; the builder_os_cache_providers filter registers others.
  • Fast measurement (4.18). builder-os-cv-measure.js measures two pages at once and each one on mobile and desktop at once (4 frames at most; 2 if the machine has fewer than 4 cores or 4 GB; if a page takes more than 12 s it drops to one at a time and returns to two when they go fast). It only waits (up to 5 s) for unloaded images that can shift the layout: without width and height in the HTML, without aspect-ratio in the CSS and without loading="lazy" (in an off-screen frame they never load, as before), so the heights are the same as with the previous method. Pages are loaded in measurement mode: ?bos_measure=<nonce bos_measure>, valid only with the session of a user who can sync packages (Builder_OS_Thumbs::MEASURE; same effect-free front end as the thumbnail: no Tracking, cookie banner, chat, popups, assignment or A/B counting, admin bar or page cache, Cache-Control: no-store); a visitor who fakes it sees the normal page. What was measured isn’t repeated: Builder_OS_Perf_Visibility::todo() gives each page a fingerprint (md5 of its content and of signature(): CSS and JS of the active packages, Global design, headers/footers and templates, theme, performance settings and BuilderOS version) and skips those already measured with the same fingerprint whose sections are still saved (builder_os_perf_heights[p]: URL ⇒ [fingerprint, keys], up to 2000). Batches are saved one after another. If nothing is left to measure, Performance says “Heights are already up to date”.
  • #id anchors: [data-bos-cv]:target and [data-bos-cv]:has(:target) force content-visibility: visible (in separate rules, so a browser without :has keeps the first). Verified: each # link on the page leaves its section on screen.
  • Browser search (Ctrl+F): Chrome and Safari reveal found text inside skipped sections. Entrance animations: their IntersectionObserver observes the section once drawn; verified that it fires on all skipped sections. Printing: everything visible (@media print).
  • A/B tests: each variant is a different cache copy and comes out with its own heights; the original’s copy (PageSpeed’s) too. Changing the measure clears them all.
  • What it can break (that’s why it starts off): paint containment clips what overflows the section (large shadows, decorations with negative margin) and a position: fixed inside it is positioned relative to the section. Exclude a section with data-bos-nocv on its root element. Don’t declare content-visibility or contain-intrinsic-size in the package’s CSS: its own wins and the reserved height would no longer be the measured one.
  • Measured (home page with 14 below-the-fold sections, Lighthouse mobile, median of 3, package CSS without its own content-visibility): score 93 → 98, TBT 280 → 130 ms; Pricing 90 → 95. Desktop: 94 → 97. CLS unchanged (0.06 before and after on desktop, from the font swap, not from content-visibility).
  • “N pages left unmeasured” notice (4.19.1). It is calculated with what is really still unmeasured when the WP-Cron fallback runs (not with the list from when it was installed) and removes itself from the bell as soon as those pages’ heights are saved, or the browser finishes the Packages screen flow (Builder_OS_Perf_Postinstall::refresh(), option builder_os_postinstall_unmeasured). Pages without their own post don’t count.

CSS per section, in detail:

  • When optimizing, the package’s stylesheet is broken into pieces in its order: rules, @media/@supports/@layer/@container blocks with their rules, and what is always kept (@font-face, @keyframes, @import, /*! licencias */, nested CSS). For each rule it records which classes and ids each selector requires (what is inside :not(), :is(), :has() isn’t required).
  • On each page with a canvas, the parts and content are painted before the <head>: BuilderOS collects the classes and ids of the HTML actually painted —including the client’s changes in the editor, repeater, query and menu items, and the <body> classes— and generates a filtered copy of the stylesheet in its original order with:
    • the global rules: no class or id (:root, body, *, img…) and the at-rules that are always kept;
    • the rules that use classes the JS can add: those that appear in classList.add/toggle, className, setAttribute('class'), addClass, in { class: '...' } objects or in the HTML generated by the package’s and BuilderOS’s JS, and state ones (is-*, has-*, active, open…); if the JS computes classes ('is-' + estado), any word in its strings counts;
    • with unknown third-party JS (a CDN other than GSAP, ScrollTrigger, Lenis, Three.js or Lottie), also the classes that don’t appear in any package template;
    • and the rules whose selectors can be satisfied by what is on the page.
  • A rule is only removed if it requires a class that isn’t on the page and that no JS can add: it can’t apply to anything on that page.
  • Each combination is saved as styles.<hash>.bos-part.css next to the sheet (immutable, like the rest) and embedded if it fits the limit; if not, it is linked.
  • When in doubt the whole sheet is served: pages without a canvas (theme templates, archives), CSS that can’t be parsed, more than 300 combinations, or ?bos_full_css=1 in the URL (useful for comparing).