lovablehtml logo - turn your SPA into a crawler-friendly websiteBLOGAPI PLATFORMPRICING

Setup with Vercel

Run middleware on Vercel that calls LovableHTML for HTML document requests and falls back to your SPA for everything else.

How it works (SPAs)

Your edge middleware/worker calls /api/prerender/render?url=... for HTML document requests. If LovableHTML returns 200 you serve rendered HTML. If it returns 304 with a Location header, prerendering didn't apply — fall back to your origin SPA.

Prerequisites

  • A LovableHTML account and API key (Settings → API Keys)
  • A domain added + verified in your LovableHTML dashboard
  • A Vercel project serving your SPA

Setup

Replace <your-api-key> (or set LOVABLEHTML_API_KEY where the snippet expects it). Don't commit API keys.

  1. Create middleware.js at the project root (same level as package.json).
  2. Set the environment variable LOVABLEHTML_API_KEY in your Vercel project settings if you did not paste a key into the snippet.
  3. Deploy to Vercel. The middleware runs on the configured matcher for every request.

How to Test

  1. Call the render API directly and verify x-lovablehtml-render-cache: hit | miss
  2. Hit your site with Accept: text/html and verify you get HTML back
  3. Verify static assets (JS/CSS/images/fonts) are not proxied to LovableHTML
bash
CopyDownload
# 1) Call the LovableHTML render API directly
curl -sS -D - -o /dev/null \
-H "x-lovablehtml-api-key: <API_KEY>" \
-H "Accept: text/html" \
"https://lovablehtml.com/api/prerender/render?url=https%3A%2F%2Fyour-domain.com%2Fyour-page"
# Look for:
# - HTTP/1.1 200
# - x-lovablehtml-render-cache: hit | miss
# - x-lovablehtml-snapshot-key: ...
bash
CopyDownload
# 2) Hit your site with an HTML Accept header
curl -sS -D - -o /dev/null \
-H "Accept: text/html" \
-A "Googlebot" \
"https://your-domain.com/your-page"
# Look for:
# - HTTP/1.1 200
# - content-type: text/html
bash
CopyDownload
# 3) Passthrough (no Accept: text/html → middleware should not call LovableHTML)
curl -sS -D - -o /dev/null \
-A "Mozilla/5.0" \
"https://your-domain.com/your-page"

Best Practices

  • Keep secrets out of git — Store keys in your platform's secret manager or env vars; rotate/revoke when compromised.
  • Don't proxy static assets — Only call LovableHTML for HTML document requests. Always pass through JS/CSS/images/fonts.
  • Handle 304 passthrough — 304 means prerendering doesn't apply. Fall back to your origin and use the Location header as the target URL when needed.
  • Invalidate after content changes — Use the cache invalidation endpoints (optionally with prewarm) after deploys or CMS updates.

Need help? Check the full API reference for prerender, cache, and analytics endpoint docs, or jump directly to Analytics API, or contact us if you run into issues.

Avatar
How can we help?
Get instant answers to your questions or leave a message for an engineer will reach out
Ask our assistant anything
See our docs
Leave a message
Leave a message
We'll get back to you soon
Book a Meeting
Select a date & time
Avatar
Support Assistant
We typically reply instantly
Thinking
Preview
Powered by ReplyMaven
Avatar
Support Assistant
Hi, how can we help?