Skip to documentation content

Performance

What the CookieBeam script downloads, in what order, how large the shared files are, how they're cached, and what keeps running after the page has loaded.

Last updated:

This page describes what CookieBeam costs a page: the files it loads, when it loads them, how browsers cache them, and what it keeps doing afterwards. The sizes are the reference figures CookieBeam checks each runtime release against.

How the script loads

CookieBeam loads in steps. Only the first one blocks the page.

  1. loader.js is the tag you install. It runs as the browser reads the page, so it can hold back scripts that come after it. When blocking is on for the banner, it contains the script-blocking code inline. Regional rules aren't evaluated here. That happens in latest.js.
  2. The loader adds latest.js to the page as a separate script. This file holds your published configuration. It picks the regional rule, using the country and region the CDN adds to the file.
  3. When latest.js has loaded, the loader adds the framework bundle, but only on banners with IAB TCF or GPP turned on.
  4. While the page is still parsing, latest.js adds preload hints for the banner stylesheet and the banner runtime, so the browser can start fetching them before DOMContentLoaded. The preload is skipped once parsing has finished and for visitors in regions where the banner is hidden. At DOMContentLoaded, it starts the banner with those files. Banners published before this change fetch the runtime and stylesheet only at DOMContentLoaded; republishing picks up the preload behaviour.

Steps 2 to 4 don't stop the browser from reading the rest of the page. The banner runtime isn't bundled into latest.js. It's a shared file, so a browser that has it cached doesn't download it again for another page.

Keep the loader tag as it is. Don't add async or defer, and exclude cdn.cookiebeam.com from script optimisers that delay or combine JavaScript. A delayed loader can't hold back the scripts that ran before it. See Load order.

To measure the difference the banner makes in each consent state (unanswered, accepted, rejected), see Performance testing.

File sizes

Reference sizes of the shared files, gzip-compressed, for runtime version 0.3.57. They're the baseline a release is checked against, so the bytes your browser receives can differ slightly:

FileSizeLoaded
Banner runtime, cookiebeam-core.umd.min.js66,452 bytes (about 66 kB)On every banner
Banner stylesheet, cookiebeam-core.css14,514 bytes (about 15 kB)On every banner
Framework bundle, cookiebeam-core-framework.umd.min.js66,917 bytes (about 67 kB)Only with IAB TCF or GPP

So a banner without TCF or GPP downloads about 81 kB of shared files, and one with TCF or GPP about 148 kB. These figures change with each runtime release.

loader.js and latest.js come on top of that. Their size depends on your banner: the script and connection inventory, blocking rules, regional rules, and the languages you customized are all written into them. There's no single figure. Check yours in the browser's network panel.

Caching

FileIn the browserNotes
loader.js, latest.jsNot cachedThe CDN adds the visitor's location to each response, so browsers are told not to store it. The CDN's own copy is kept and cleared when you publish
Banner runtime, stylesheet and framework bundleAt least 1 hourShared by all banners that use the latest runtime
Pinned runtime files1 year, immutableBanners with consent purposes turned on load a fixed runtime version
known.json1 day

A returning visitor inside those windows gets the shared files from the browser cache. loader.js and latest.js are requested on every page view.

Languages

latest.js includes the banner's default language and every language you customized. The other platform languages are loaded on demand, one file per language.

When a visitor needs one of those languages, the runtime fetches it before it shows the banner. It waits at most 2.5 seconds. If the file hasn't arrived by then, the banner shows in the default language for that page view. It isn't switched when the file arrives later.

If most of your visitors read a language you haven't customized, that fetch delays the banner for them. Customizing a language includes it in latest.js, at the cost of a larger file for everyone. See Languages.

Visitor location

The CDN adds the visitor's country and region to latest.js, so the regional rule costs no extra request. If the location is missing and regional settings are on for the banner, the script makes one extra request and waits at most 800 milliseconds before it falls back.

What keeps running after load

CookieBeam doesn't stop working once the banner is on screen. Blocking has to watch the page for as long as it's open.

  • Wrapped DOM methods. With blocking on, the loader wraps the methods that insert content into the page: appendChild, insertBefore, replaceChild, before, after, replaceWith, append, prepend, replaceChildren, insertAdjacentElement, insertAdjacentHTML, innerHTML, setHTML and attachShadow. With script blocking on, it also hooks setAttribute and the src and srcset setters of script, iframe, image and embed elements. These run inside every such call your page makes. This is the main way scripts are caught.
  • A MutationObserver on the whole document. With blocking on, the loader also watches for added elements and for changes to src, srcset and type attributes. It's a backstop for markup the browser's parser inserts.
  • Cookie and storage guards. On banners with consent purposes turned on, the loader redefines document.cookie, wraps Storage.prototype.setItem, and where the browser supports it replaces window.localStorage and window.sessionStorage with a proxy. Every cookie write and every storage write on the page passes through them.
  • Wrapped browser functions. With connection blocking on, or on banners with consent purposes turned on, the loader wraps fetch, XMLHttpRequest, navigator.sendBeacon, WebSocket and EventSource to check each request's address.
  • A second observer for drift. On plans with Tracker Tripwire, the drift reporter watches for added scripts, iframes and images, and wraps the same network functions to see new destinations. It also re-reads cookie names two seconds and ten seconds after it starts, after a consent choice, and when the tab becomes visible again.

If you see CookieBeam in a performance profile, look at the wrapped DOM methods first, then the cookie and storage guards on purpose banners. They run synchronously, inside your page's own calls, so a page that inserts many elements or writes cookies often pays for them most. The observers run later, in batches.

Background requests

A returning visitor with a stored choice doesn't see the banner, but the script still loads and can still send reports:

  • Drift reports, batched about two seconds after something new is seen, and when the page is hidden or closed. One page sends at most 20 batches.
  • One load-order report after the page has loaded, when there's something to report.
  • An impression, at most once, when the banner is shown. Impressions can be sampled.
  • A consent record, when a choice is made.

Runtime security and data flows lists what each one carries.