Skip to main content

In Thoughts

Pretext and the Problem I Didn't Know Existed

2 min read

I have been building web and mobile UI for a while and… I thought I had a decent reads on how browsers actually work under the hood. Then I came across Pretext last week and found out I’d been wrong about something for years without even knowing to question it.

So basically, every time a browser needs to know how tall a block of text is, reading that measurement can trigger a layout recalculation, forcing the browser to resolve all pending style and position changes before it can give you an answer. It's a well-known gotcha, but it's so baked into how the DOM works that most of us just accept it and move on.

Pretext, built by Cheng Lou, just doesn’t do that. It reads character size straight from the font engine, some skeptical about this since it just use canvas.measureText and works out the layout with math. I am agree, but this getting interesting when I try to dig out. Where it doesn’t need DOM and no reflow, and the library is 15KB. Apparently it ends up being faster than the browser’s native approach.

The performance alone is impressive, but what actually got me was watching what people started making almost immediately after it dropped. Within the same week:

A dragon of the house targaryen is on the browser baby

A 3d castle, rendered with text along it

A fairy conjuring magic through typography

These weren’t polished products. Just people who grabbed the library the same week it came out and went straight to the FUN part.

And that's the real reminder here, a solid engineering foundation combined with the right tools means the gap between "idea" and "working thing" keeps shrinking. The best engineers aren't just getting faster at building; they're spending more time on the part that actually matters.


I build interfaces for a living. I talk about performance and UX regularly. And I genuinely had no idea this was a thing until last week. That's a weird feeling, a reminder that there's still a lot of floor to lift up.

Read next