High-traffic Bank of Georgia public site, 4 min read
Prerendering middleware
Built an Express middleware that gives search crawlers finished, script-free HTML from the same origin that serves people. The key decision was forcing the shadow-DOM polyfill so content built from custom elements serializes.
The problem
Bank of Georgia's public site was a SPA built from custom elements, and after the micro-frontend split every page arrived through a runtime import(). Search visibility is a hard requirement on that surface, so it needed to stop depending on crawlers executing a federated module graph.
The approach
A middleware in the site's own Express process gives crawlers pre-rendered pages. A new site adopts it as a dependency plus a small config block.
request ───▶ express app ───▶ prerender middleware
│
people ◀── SPA shell ──┤
│ search crawlers
▼
render · strip scripts · serialize
▼
finished HTMLKey decisions
Forcing the shadow-DOM polyfill
Nearly all rendered content lives inside shadow roots, which aren't part of serialized markup, so a plain render returns a document of empty tags. Forcing the legacy polyfill before any app code runs makes components render into the light DOM. It is opt-in per site.
Running the middleware inside the app
Crawlers and people use the same URL on the same origin, served by the same deploy. That means no second hostname and no edge rules to keep in sync with app routing.
Removing scripts, keeping structured data
Scripts are removed before serialization so the SPA doesn't boot again on the crawler's side. The selector is deliberately narrow, which keeps application/ld+json structured data in place.
Caching and capping renders
Rendered HTML is cached and cleared on every deploy, so most crawler requests never start a browser. Renders run through a capped queue with a time budget. When the queue is full, crawlers are asked to retry later, and a render that runs too long is abandoned, so the crawler gets the SPA shell instead of an error.
export const prerender = ({ isCrawler, cache, renderer }) =>
async (req, res, next) => {
if (req.method !== "GET" || !isCrawler(req)) return next();
let html = await cache.get(req);
if (!html) {
html = await renderer.render(req); // queued, with a time budget
await cache.set(req, html);
}
res.type("html").send(html);
};Impact
- Indexed pages on the main site rose 46%, from about 1,140 to 1,670, comparing eight weeks before rollout with eight weeks after.
MeasuredThe “Indexed” count in Google Search Console's Page indexing report for the main site's property.
- About 82% of crawler requests are served from the cache.
MeasuredHit and miss counters the middleware emits on every crawler request, summed in Grafana over 30 days.
- A cold render takes about 1.8 s at p95.
MeasuredRender time the middleware logs for every cache miss, p95 in Kibana over the same 30 days.
- Rolled out to five public sites as one versioned package, with crawlers receiving complete HTML for content that otherwise existed only after JavaScript ran.
- Routes could move into micro-frontends one at a time without depending on the client-side module graph for search.
- The same HTML feeds site search and the AI summary card.
Trade-offs
What it cost
- Two rendering paths to keep correct: a component that breaks under the forced polyfill breaks only for crawlers, where nobody sees it.
- Because rendered pages are cached, a content fix can take hours to reach crawlers unless someone deploys.
What I’d change
- Render the most important pages at deploy time, and keep on-request rendering for the long tail.
- Add a CI check that renders key pages in polyfill mode and fails on empty output.
What came next
The sites are now moving to server-side rendering with React and Lit SSR, site by site, and the middleware keeps serving each site until it moves. Lit SSR renders shadow roots on the server as Declarative Shadow DOM, so the content is in the markup from the first byte with no polyfill.
Connected work
These case studies are parts of one platform. This one connects to: