Dev.to WebDev 🛠 Dev 👁 0 📖 4 min read

My SSR pages were shipping 2.3 MB of HTML — how I found it and cut 92%

Last week, Google Search Console dropped our site's indexed page count from 145 down to 80, with 63 URLs sitting in "Crawled - currently not indexed" and impressions flatlining to almost zero. My first assumption was co

My SSR pages were shipping 2.3 MB of HTML — how I found it and cut 92%

Last week, Google Search Console dropped our site's indexed page count from 145 down to 80, with 63 URLs sitting in "Crawled - currently not indexed" and impressions flatlining to almost zero.

My first assumption was content thinness or link authority. It turned out to be something much more mechanical: every single SSR page on our site was shipping 2.33 to 2.39 MB of raw HTML — right past Googlebot's ~2 MB HTML parsing cutoff (2,097,152 bytes).

Here is how I profiled the exact bytes inside a TanStack Start + Nitro + Cloudflare Workers + D1 app, fixed a subtle SSR fallback bug along the way, and brought HTML down by 89%–92.6% without breaking client interactivity.

1. How I spotted the 2.39 MB HTML payload

The site looked fast enough in Chrome with brotli compression over localhost. The problem only jumped out when I fetched raw SSR documents with a minimal Python script (no JS execution, just what a crawler sees first):

import urllib.request

for path in ["/", "/photo-to-gif", "/photo-to-sketch", "/pricing"]:
    req = urllib.request.Request(
        f"https://liofx.com{path}",
        headers={"User-Agent": "Mozilla/5.0"},
    )
    raw = urllib.request.urlopen(req).read()
    print(f"{path:20s} -> {len(raw):,} bytes ({len(raw)/1024:.1f} KB)")

The output was brutal:

  • / -> 2,447,360 bytes (2,390 KB)
  • /photo-to-gif -> 2,406,400 bytes (2,350 KB)
  • /pricing -> 2,385,920 bytes (2,330 KB)

Even /pricing, our Photo to Sketch workspace, and our purely browser-local Photo to GIF converter — which doesn't even call a cloud AI model — were shipping over 2.3 MB of HTML before a single stylesheet or script ran.

Raw SSR HTML size before vs after optimization across 5 production routes

2. Profiling what was actually inside the HTML

Next, I broke down <script> tags vs visible markup inside the SSR document:

  • Visible HTML markup + head metadata: ~42 KB
  • TanStack Router dehydrated loader payload (__TSR__ / inline state): ~2.29 MB

Breakdown of the 2.39 MB dehydrated SSR payload inside raw HTML

Inside that dehydrated JSON, one field was responsible for almost 2.0 MB by itself:

Culprit #1: 9,531 pricing rows serialized into every route (~1.95 MB)

Two days earlier, we had seeded 93 AI image and video models into Cloudflare D1 along with 9,531 granular per-option pricing rows (yirRates) so the studio UI can display exact credit quotes before users run a job.

Because our shared pageData() loader fetched the full model catalog and returned it inside SSR loader data, every public route was dehydrating all 9,531 pricing rows into the HTML document — even pages that only run locally in the browser!

Culprit #2: Server-only routing tables and duplicate nav trees (~239 KB)

After stripping yirRates from SSR and moving the full catalog to a client-side TanStack Query endpoint (/api/catalog, staleTime: 5 min), I re-measured.

HTML dropped from 2.39 MB to 391–463 KB — much better, but still heavier than I wanted for a clean <300 KB target. A second pass inspecting top-level keys inside the dehydrated state revealed three more leaks:

Dehydrated key Size in SSR HTML Actually needed on client?
directory.routes 78.5 KB No — server-side route lookup map only
directory.navigation 111.0 KB Duplicated full tools list + unused long descriptions
templates.items 49.5 KB Unused on non-template tool pages

Slimming those three payloads in the SSR loader (while leaving the shared directory builder untouched for server/sitemap generation) shaved off another ~220 KB per page.

3. The sneaky regression I caught during verification

Stripping yirRates from SSR had one subtle side effect worth sharing if you run SSR with dynamic pricing or feature flags.

On tool pages that compute exact single-photo credit quotes during SSR (like our Clay Animation and Chibi style workspaces), removing yirRates from the SSR model list initially made the server think zero models were priceable — rendering a "temporarily unavailable" fallback string directly in SSR HTML (which Google can read as a Soft 404!).

The fix had two parts:

  1. Keep only the 1 matched compatible model's yirRates in SSR on exact-pricing tool pages (cost: ~3–6 KB instead of 1.95 MB), while lazily hydrating all 93 models on the client via /api/catalog.
  2. Fix a pre-existing model filter condition (!m.managedYir || ordinary || (!!tool && hasExactToolPricing(tool.id))) that had been accidentally excluding managed-pricing models on 30 tool pages in production.

Running an automated SSR scanner across every public URL confirmed all 30 pages flipped from unavailable=True back to unavailable=False while staying under 205 KB.

Zero Soft-404 SSR model hydration architecture comparing single matched SSR model vs full client catalog hydration

4. Before vs. After (measured on production Cloudflare Workers)

Page Before (raw SSR HTML) After (raw SSR HTML) Reduction
/ (Home) 2,390 KB 249 KB -89.6%
/photo-to-gif 2,350 KB 175 KB -92.6%
/photo-to-sketch 2,348 KB 177 KB -92.5%
/clay-animation 2,360 KB 201 KB -91.5%
/pricing 2,330 KB 173 KB -92.6%

Client behavior stayed identical: once hydrated, /api/catalog loads all 45 image models and 48 video models cleanly with zero console errors.

5. Bonus: Keeping browser tools genuinely zero-upload

While untangling server vs. client boundaries, we also extracted the pure client-side GIF89a encoder logic (zero external dependencies, median-cut quantization + LZW stream writer) into a tiny standalone MIT repo so anyone can inspect how browser-only GIF encoding works without uploading files to a server:

Takeaways if you run SSR + TanStack / Next / Remix

  1. Always inspect uncompressed SSR HTML bytes, not just compressed DevTools transfer size. Crawlers care about decoded document size and truncation thresholds.
  2. Audit your dehydrated state keys after every database/catalog expansion. One innocent SELECT * in a shared root/page loader can silently multiply every route by 10x.
  3. Always run a post-slim SSR scan for fallback/empty-state strings ("unavailable", "not found", "loading...") so trimming SSR data doesn't accidentally introduce Soft 404s.

If you've ever been bitten by invisible loader bloat in SSR frameworks, I'd love to hear what bloated your HTML the most in the comments!

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.