in
Written by Harry Roberts on CSS Wizardry.
View this web page as Markdown.
Desk of Contents
Unbiased writing is dropped at you through my fantastic
Supporters.
One factor I encourage all of my purchasers to recollect is that net efficiency
occurs someplace between you and your person. The very same web page on the precise
identical infrastructure can really feel vastly completely different to 2 completely different folks, and
realizing the place the 2 meet is essential to designing actually quick experiences.
Over the previous couple of years, I’ve written a good bit about excessive latency
environments and low-
and mid-tier cell,
and one of many recurring themes in each is that site-speed is just partly a
property of the positioning itself. A big a part of it’s a property of the
situations beneath which that web site is being consumed.
Generally, net efficiency actually is a them downside.
It’s not our fault that somebody is on a struggling connection, a weaker gadget,
or a battery that’s almost lifeless, however it’s nonetheless our duty to design
round these eventualities the place we will. To assist, I constructed Obs.js,
a tiny library which tells us a big quantity about our customers’ context.
I launched Obs.js in summer time 2025, and whereas it’s been extremely helpful and
insightful (instrumental, even) on a number of consumer tasks, I haven’t actually
talked about it a lot since then. At present, I’ll.
In order for you the extra direct technical walkthrough, I’ve written that up
in Obs.js:
Context-Conscious Net Efficiency for Everybody. This piece is the
companion to that one. That is much less concerning the API itself and extra about why
I believe having this kind of sign out there to us issues.
A Actual Instance
Obs.js reads browser alerts about our customers’ connection, gadget functionality,
battery standing, and extra. We are able to then use this data to adapt and tailor
our front-end code to go well with their situations. And whereas I can’t share consumer work
right here, I can share a small however very actual instance of my very own.
On my homepage, I exploit Obs.js to change the masthead imagery relying on the
browser’s inferred supply mode. Within the sooner case, I exploit the complete, high-res
picture stack:
.page-head--masthead {
background-image:
url(/img/css/masthead-small.jpg),
url(/img/css/masthead-small-lqip.jpg),
var(--base64);
}
And if Obs.js decides the customer is healthier served by lite mode, I drop down
to the LQIP-only variant:
.has-delivery-mode-lite .page-head--masthead {
background-image:
url(/img/css/masthead-small-lqip.jpg),
var(--base64);
}
There’s nothing massively subtle happening right here, and that’s precisely why
I prefer it. I’m not making an attempt to construct some elaborate adaptive-delivery system; I’m
simply making a small adjustment in response to a sign from the browser.
The web page remains to be the identical web page, on the identical infrastructure, served by the identical
code. Just one customer will get the richer masthead stack, and one other will get the
LQIP-only model. The distinction lies not in my utility however within the
context wherein it’s being considered.
What I discover reassuring is that this isn’t creating some kind of second-rate
expertise for guests in lite mode, and, fortunately, the numbers show it:
SpeedCurve exhibits that throughout 3,777 web page views in
lite mode and 4,965 in wealthy mode, Largest Contentful
Paint is just 80ms aside!
Nearly similar experiences.

lite and wealthy cohorts, LCP stays inside 80ms, whereas INP and CLS are similar.I make related variations with my nav—customers with low- or critically-low battery
is not going to be proven any superfluous animations, and as an alternative simply have a a lot
easier open/closed expertise. Each little helps, and I can adapt to suit.
Your Web site Is Solely Half the Story
What I like about Obs.js is that it is vitally trustworthy about the issue it’s
addressing. It’s not pretending to make weak units stronger or poor networks
sooner; it can not scale back the gap between anyone and your servers, extend
battery life, or improve their handset from throughout the confines of a browser
tab. However what it will possibly do is give us a barely clearer image of the situations
beneath which our work is being skilled.
It reads a handful of browser alerts—latency, bandwidth, Knowledge Saver, battery,
CPU, reminiscence—and exposes them as lessons on the <html> ingredient and as a small
window.obs object in JavaScript. This straightforward performance opens up an entire
world of potential, and it’s as much as us as builders to use it.
The worth just isn’t that it makes choices for us—it doesn’t—the worth is that it
offers us higher data with which to make our personal choices. Maybe that
means avoiding wealthy media; maybe it means serving decrease decision imagery.
Maybe it means firming down movement; maybe it means holding again an internet font.
The precise response remains to be as much as us, correctly, however we get to interchange
a bit guesswork with a bit proof.
Keep in mind, net efficiency is partly about you, and partly about them. Previous to
Obs.js, there wasn’t a lot we may do to learn about them till it was too
late.
Statuses and Stances
The library makes the excellence between Statuses and Stances.
A Standing is factual: the person has Knowledge Saver enabled, the noticed latency
is excessive, the battery is low, the gadget is weak. A Stance is the
opinion we derive from that: the connection seems weak, the person might favor
to preserve sources, the most secure supply mode is lite, wealthy media is
most likely not an incredible thought proper now.
That distinction issues as a result of it retains uncooked alerts separate from opinions and
choices. Generally I would like the low-level data as a result of I already understand how
I wish to react to it. At different instances, I’m completely completely satisfied for the library to
have an opinion and hand me one thing a bit extra usable, comparable to
deliveryMode, canShowRichMedia, or shouldAvoidRichMedia.
This can be a good degree of abstraction to have as a result of it leaves room for each
approaches. If you wish to be opinionated your self, you might be. When you would
quite begin from an honest default and get on with it, you are able to do that, too.
Thoughtful, Not Intelligent
I don’t assume this kind of work is attention-grabbing as a result of it makes websites really feel
intelligent. I believe it’s attention-grabbing as a result of it offers us a greater shot at making
them really feel extra thoughtful.
It is extremely straightforward to ship the heaviest potential model of an expertise by
default just because our personal machines can tolerate it. It is extremely straightforward to look
at a function in isolation and determine that, sure, clearly the autoplaying
video or the heavy animation or the higher-resolution picture can be higher if
circumstances are best, however what if we had a greater thought of whether or not
circumstances truly are best?
That’s the bit I care about. It shifts us away from asking can we ship
and extra towards asking
this?ought to we ship this to this customer, beneath
The reply might usually nonetheless be sure, however not less than
these situations, proper now?
we’re asking the query.
Understanding Your Viewers
One of many much less flashy however nonetheless very sensible unwanted effects of Obs.js is that
it doubles as a segmentation layer to your analytics. In case your tooling helps
customized dimensions, you possibly can beacon among the Obs.js alerts off alongside the
remainder of your efficiency information and cease treating your viewers as one opaque
common.
At that time, you can begin asking far more helpful questions. How a lot worse
is INP for weaker units? What quantity of your site visitors is on
high-latency connections? How usually are you seeing Knowledge Saver within the wild? Are
guests in lite supply mode behaving otherwise? Even when you by no means adapt
a single byte of the UI, that’s nonetheless helpful data to have as a result of it
offers you a richer image of who your customers truly are.
For instance, whereas INP is a developer’s downside to resolve, it’s extremely
influenced by the facility of the gadget getting used. Identical code, three completely different
scores:

Generally, it’s a them-thing.
This has helped me immensely in latest tasks the place we had unknown unknowns
that left us utterly in the dead of night. Understanding if it’s an us-problem or
a them-problem can utterly change the course of an engagement, and it has!
One specific venture confirmed us that conversion charges have been larger amongst customers
with low or vital battery. This hints at a possible sense of urgency, so
maybe we adapt the checkout stream to take away as a lot pointless friction as
potential, delivering absolutely the most bare-minimum checkout expertise we will.
Browser Help and Limitations
A lot of the underlying APIs are Chromium-heavy. Safari, particularly, just isn’t
going to inform you very a lot, and I do not likely see that as a flaw in Obs.js so
a lot as a reminder of the bounds of what the platform at the moment exposes. Obs.js
is progressive enhancement at its most interesting, so deal with it as an additional vector quite
than a baseline.
The library doesn’t fake to know what it can not know. It offers you the
alerts it will possibly get, and it leaves the fallback coverage as much as you. Perhaps your
default is the richer expertise and the browser helps you dial issues down
the place wanted, or possibly your default is the lighter expertise and the browser
helps you selectively dial issues up. Both strategy is affordable, the
essential factor is that the choice turns into specific quite than unintended.
A Very Sensible Concept
There are numerous good concepts in net efficiency that stay simply barely too
educational, or barely too fiddly, to make it into actual work. Obs.js tries to
keep away from that downside.
It’s tiny, it offers you a bit extra context than you’d in any other case have, and
it asks little or no in return. Paste it into the <head>, have a look at the lessons
it provides, and begin making small choices from there: serve the smaller picture,
skip the autoplay, keep away from the customized font, tone down the movement, defer the
nice-to-have. None of these are particularly dramatic interventions, however they’re
smart changes made with a bit extra data than we normally have.
That’s the reason I prefer it a lot. It offers us a sensible and trustworthy strategy to
acknowledge a reality that has at all times been there: efficiency doesn’t occur in
a vacuum, and the entrance finish doesn’t arrive on the person unchanged by the journey
it took. When you’ve got by no means checked out Obs.js earlier than, go and play with the
demo, try the
repo, and examine
obs.js itself.
I believe the underlying thought is a helpful one whether or not you utilize my little library or
not.
When you’re already utilizing Obs.js, open a Pull
Request to submit your web site to the
showcase.

