Blog ·
Your analytics script was probably the first thing you added to your site, and it's the last thing you'll ever check. Meanwhile it charges every visitor in bytes, blocked rendering and extra round trips. Here's how to see what yours costs in five minutes, and what the alternative looks like at about 1.3 KB.
Four ways a script slows a page
- Bytes. Every visitor downloads your script. The bytes cost nothing on office fibre, and an eternity on one bar of signal in a train tunnel.
- Blocking. A plain
<script src>in the<head>(the top of your HTML) stops the browser building the page until the script has downloaded and run. Until then, your visitor is looking at a blank or half-drawn screen. - Main-thread time. A browser runs a page's scripts on its main thread, the same one that handles taps and scrolls, and it does one thing at a time. While a script runs, the page can't respond to taps. A tag manager (a script whose job is loading more scripts) plus a consent tool (the cookie pop-up) plus a session recorder (which logs every click and scroll) can keep a mid-range phone busy for hundreds of milliseconds.
- Extra round trips. A round trip is one message to a server and its reply, and on a phone each one can take a tenth of a second. A new domain means looking up its address (DNS), opening a connection (TCP) and setting up encryption (TLS) before the first byte arrives. Then there's CORS, the browser's rules for sending data to a different site. Any request with custom headers (extra labels attached to it) triggers a CORS preflight: an
OPTIONSrequest asking permission before the real one, which doubles the round trips for every event the script records.
Check yours in five minutes
Open your site in Chrome, open DevTools (right-click the page and choose Inspect), go to the Network tab, which lists every file the page downloads, and reload.
- Filter by your analytics domain and add up the Transferred column (the bytes that actually came down the wire), including any scripts it went and fetched on its own.
- Check the script tag for
deferorasync. Both let the browser keep building the page while the script downloads. Without either, it blocks your page. - Look for
OPTIONSrequests. Each one is a preflight, and a wasted round trip. - Run Lighthouse, Chrome's built-in page-speed audit, from its tab in DevTools. "Reduce the impact of third-party code" lists every script loaded from someone else's servers, with its size and main-thread time. It's remarkably candid.
Then do it again with throttling set to Slow 4G, a dropdown in the Network tab that makes Chrome pretend it's on a weak mobile connection. That's much closer to what your visitors get than what you get at your desk, three feet from the router.
What 1.3 KB looks like
When we built Foresite's tracking script, page weight was the one rule we wouldn't bend. Our customers run Webflow, Squarespace and WordPress sites, and plenty of them check Lighthouse the way other people check the weather.
- About 1.3 KB gzipped, smaller than most favicons (the little icon in a browser tab). Gzip is the compression servers apply on the way out, so that's the size that actually travels. It's about 180 lines of TypeScript with no dependencies, meaning no one else's code bundled in.
- Loaded with
defer, so it never holds up rendering, the browser drawing your page. - One request per pageview, and one when the visitor leaves the page, with no preflight.
fetchis how a script sends data in the background. Sending plain text with no custom headers keeps it a CORS "simple request", which goes straight through without asking permission first. keepalive: true, which tells the browser to finish sending even after the page closes. So the event still gets sent when a visitor clicks away, without making them wait.- No entourage. No tag manager, and no cookies.
It's open source, and its tests run against the same minified bytes the server sends: the version with spaces stripped and names shortened, not the tidy source. Don't take our word for the numbers. Don't take anyone's.
Whatever you use, use defer
If you're keeping your current analytics, the cheapest speed-up available is adding defer to its tag. async and defer both download in the background, but they run at different times. An async script runs the moment it arrives, which can interrupt the browser halfway through the page. A defer script waits until the page is built.
And if Lighthouse names your analytics among your heaviest third parties, ask what you're getting for all that weight. Pageviews, sources (where visitors came from) and conversions (the sign-ups and sales you're after) don't need much. The rest is features you may never open, and your visitors carry them on every page.