agentleFS
charanjit-singhcharanjit-singh/lovable-skills/skills/seo-ssr-and-prerendering/SKILL.md

seo-ssr-and-prerendering

Skill10 starsChanged 6 months agoMITView on GitHub

Use when a Lovable SPA needs Google or social crawlers to see populated HTML: SSR, prerendering, react-snap, prerender.io, vite-ssg, or migrating routes to static. Not for fully authenticated apps with no public surface.

  • Installs packages

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 4 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Start with prerendering; move to SSR only when content changes too fast for a rebuild.

    line 24
  2. Distinctive:

    If you can't change the build pipeline:

    line 54
  3. Distinctive:

    Add a serverless function or middleware that detects bot User-Agents and proxies to prerender.io.

    line 56
  4. Distinctive:

    Don't prerender a "loading…" shell.

    line 79
  5. Very specific:

    Use tanstack-prefetch-and-hydration to embed a dehydrated cache and hydrate on the client without a refetch flash.

    line 82
  6. Very specific:

    Do not prerender authenticated routes (/app, /dashboard, /settings) — they should redirect to login.

    line 93

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

SEO SSR and prerendering

Lovable apps are Vite + React SPAs. Crawlers and link-preview bots see an empty <div id="root"></div> until JS runs. Public marketing pages must ship populated HTML — Google does run JS, but indexing is slower and less reliable than HTML-first; Twitter/LinkedIn/Slack/Discord bots do not run JS at all.

Companion skills: seo-meta-tags-spa, seo-landing-page, tanstack-prefetch-and-hydration, programmatic-seo-pages.

When to use what

Site typeRecommended approach
Marketing site + blog + a few public routesBuild-time prerender (vite-plugin-prerender, react-snap, or vite-ssg)
Hundreds/thousands of pages from data (locations, comparisons)Static generation (vite-ssg with route iterator)
Truly dynamic public pages updated minute-to-minuteSSR via a Node server (Cloudflare Pages Functions, Vercel, Render)
Hybrid: SPA app + a few public marketing routesPrerender just the public routes

Start with prerendering; move to SSR only when content changes too fast for a rebuild.

Build-time prerender (vite-ssg pattern)

// vite.config.ts
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

export default defineConfig({
  plugins: [react()],
  // vite-ssg config in package.json or its own file
});
// src/main.tsx
import { ViteSSG } from "vite-ssg";
import App from "./App";
import { routes } from "./routes";

export const createApp = ViteSSG(App, { routes }, ({ app, router, isClient, initialState }) => {
  // hydrate or set up per-app state
});

For each public route, expose an includedRoutes generator that lists URLs (e.g. one per blog post slug, one per location).

Prerender service (prerender.io / Browserless)

If you can't change the build pipeline:

  1. Add a serverless function or middleware that detects bot User-Agents and proxies to prerender.io.
  2. Prerender.io caches the rendered HTML and serves it to crawlers.

This is fine as a stopgap but slower and not free at scale.

react-snap (alternative, low-effort)

npm i -D react-snap
{
  "scripts": { "postbuild": "react-snap" }
}

Edit index.html to use hydrateRoot instead of createRoot so the prerendered HTML hydrates cleanly.

Caveats: react-snap is unmaintained but still works for static SPAs.

Hydration with data

Don't prerender a "loading…" shell. Either:

  • Fetch data at build time and pass it through, or
  • Use tanstack-prefetch-and-hydration to embed a dehydrated cache and hydrate on the client without a refetch flash.

Routes to prerender — checklist

  • / (home)
  • /pricing
  • /blog and every /blog/[slug]
  • /about, /contact, /changelog, /legal/*
  • Programmatic templates (/integrations/[tool], /locations/[city]) — see programmatic-seo-pages
  • 404 page (/404.html)

Do not prerender authenticated routes (/app, /dashboard, /settings) — they should redirect to login.

Verify

For every public URL, raw HTML must include the title, meta, and main content:

curl -A "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" \
  https://your-domain.com/pricing | grep -iE '<title|<h1|og:title'

Also check Twitter card / Open Graph rendering: https://cards-dev.twitter.com/validator, https://developers.facebook.com/tools/debug/.

Avoid

  • Shipping a Lovable marketing site as a pure SPA and hoping Google figures it out.
  • Prerendering authenticated routes and leaking dashboard chrome to crawlers.
  • Different HTML for bots vs users (cloaking) — Google penalizes.
  • Forgetting hydrateRoot after introducing prerender — causes a re-render flash.

Checklist

  • Every public route ships with title, meta, h1, and primary copy in raw HTML.
  • OG image and Twitter card validated in third-party debuggers.
  • Auth routes excluded from prerender.
  • Sitemap and robots.txt in sync with prerendered URL list (seo-sitemap-generation).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.