Consumer recommendations site · On-device ML · SSR performance
Face-aware hero banners for 2 million+ pages
A centered crop was cutting people's heads off. I find the focal point once on the server, with no GPU and no paid vision API, and one CSS value keeps it in view.
- entries in the People category
- 2M+
- entries in the People category
- GPUs or paid vision APIs
- 0
- GPUs or paid vision APIs
- analysis budget per batch of images
- 1.5 s
- analysis budget per batch of images
- widest banner aspect handled
- 3.5×
- widest banner aspect handled
Try it
Same photo, same CSS, one different number
My own portrait in a hero banner. Drag to make the banner wider. The default crop keeps the centre; the focal point keeps the face, using the conversion from part one.


Problem
If you open the Leonardo DiCaprio page, you expect to see Leonardo DiCaprio.
People pages use wide hero banners built from uncontrolled sources like Wikimedia. A centered CSS crop on square portraits was literally cutting people's heads off, so the workaround had been to blur the banners.
Constraints
Pages are server-rendered, so analysis can't slow them down or break them.
No GPU and no paid vision API.
We don't re-encode images.
Approach
Detect a focal point once on the server with a chain of detectors in Node, using TensorFlow.js on WebAssembly: faces, then the main person's head, then saliency. A hero banner crops hard, so it only moves for a face or a person; a saliency guess keeps the default center. Logos get a separate method.
On the client, a single CSS object-position value keeps the point in view, from narrow mobile up to a banner 3.5× wider than tall.
For SSR safety: a ~30-day per-image cache, shared in-flight analysis, lazy-loaded ML libraries, and a 1.5-second budget per batch of images that falls back to the default crop.
Key decision
Prototype instead of debating
When a disagreement is about facts, a prototype settles it faster than a debate.
I built a prototype in about a day and showed the pages side by side.
Results
- The blur is gone. Faces show across the whole People category of 2 million+ entries.
- Page load is unchanged, and we never re-encode a single image.
What I'd do differently
The first visitor to a new image still gets the default crop. I'd warm the cache when images are ingested.
One point per image can't serve two very different subjects at far-apart aspect ratios. I'd store a focal box, as the logo path already does.
The detectors don't know which person the page is about. On a poster with two actors, the crop frames both.
Stack
- Node.js
- TensorFlow.js (WASM)
- Next.js SSR
- CSS object-position