Most SEO problems I inherit on Nuxt projects are not content problems. They are plumbing problems: a sitemap generated once at build time and never updated, canonical tags that keep every ?utm_ and ?sort= variant alive, and Open Graph images that return an HTML 404 page instead of a PNG. If your catalog, listings or case studies live in a database, those three outputs should come from the same database, at request time, with sane caching.
I run Loop Origin, a software studio, and as a Principal Software Engineer I have spent nine years shipping Laravel, Vue and Nuxt applications. I wrote this with help from AI tools and checked every command, header and code sample myself. This guide shows how I generate sitemaps, canonicals and OG images from the backend, with real HTTP output, a comparison of approaches and the failure modes I see in production.
How should a Nuxt app generate sitemaps, canonicals and OG images?
Direct answer: Generate all three from your backend data at request time. Serve sitemap.xml from a Nitro server route backed by your API, set one normalised canonical URL per page with useHead, and render OG images through a cached image endpoint that returns image/png. Cache aggressively and invalidate when content changes.
Why build-time SEO files break on dynamic sites
A static sitemap.xml is fine for a ten-page brochure site. It breaks the moment content changes without a deploy:
- A new product, listing or blog post goes live, but crawlers do not see it in the sitemap until the next build.
- A deleted page stays in the sitemap and returns 404, which wastes crawl budget and looks sloppy in Search Console.
-
lastmodvalues become the build date for every URL, which tells crawlers nothing useful.
The same is true of OG images rendered by a designer once per template. They go stale when the title changes, and nobody notices until a sales lead shares a link in Slack and the preview shows last year's headline.
If you are still deciding how much of the app to server-render in the first place, my earlier comparison of Nuxt 3 rendering modes for B2B SaaS covers that trade-off. Everything below assumes the public pages are SSR or hybrid.
What good looks like in real responses
Before writing code, I check what mature sites return. Here is curl output from Nov 15, 2026.
GitHub renders a dynamic OG image per repository and caches it hard:
$ curl -sI "https://opengraph.githubassets.com/932c33d9.../laravel/framework" \
| grep -iE "^HTTP|content-type|cache-control|content-length"
HTTP/2 200
cache-control: public, max-age=21600, immutable
content-type: image/png
content-length: 48567
Nuxt's own documentation site serves a generated sitemap with the right content type:
$ curl -sI https://nuxt.com/sitemap.xml | grep -iE "^HTTP|content-type"
HTTP/2 200
content-type: text/xml; charset=UTF-8
$ curl -s https://nuxt.com/sitemap.xml | grep -o "<loc>" | wc -l
883
Three things to copy: a real 200, an image or XML content type, and an explicit cache policy. The failure I find most often in audits is the opposite: an og:image URL that returns HTTP 404 with content-type: text/html, so every social share silently falls back to no image.
Approaches compared
| Approach | Fresh after content change | Scales past 50,000 URLs | Ops effort | Best fit |
|---|---|---|---|---|
Static files in public/
|
Only on redeploy | Manual splitting | Very low | Brochure sites |
Build-time generation (nuxi generate) |
Only on rebuild | Yes, with index | Low | Docs, small blogs |
| Nuxt SEO modules with an API source | Yes, with cache TTL | Yes, built-in chunking | Low to medium | Most Nuxt apps |
| Custom Nitro server routes | Yes, event-driven | Yes, you write the index | Medium | Catalogs, marketplaces, multi-tenant |
| Laravel backend generates, Nuxt proxies | Yes | Yes | Medium | Teams with backend-owned SEO data |
I default to custom Nitro routes when the data model is unusual (multi-tenant, per-locale, per-vendor) and to a module when the site is standard. The sitemap protocol limits each file to 50,000 URLs and 50 MB uncompressed, so anything larger needs a sitemap index either way.
Sitemap from the database
The backend exposes a lean, paginated endpoint. In Laravel:
// routes/api.php
Route::get('/seo/urls', function (Request $request) {
$page = max(1, (int) $request->query('page', 1));
return Product::query()
->where('status', 'published')
->select(['slug', 'updated_at'])
->orderBy('id')
->forPage($page, 45000)
->get()
->map(fn ($p) => ['loc' => "/products/{$p->slug}", 'lastmod' => $p->updated_at->toDateString()]);
})->middleware('cache.headers:public;max_age=900');
Nuxt serves the XML from a Nitro route with a cache in front:
// server/routes/sitemap/[page].xml.ts
export default defineCachedEventHandler(async (event) => {
const page = Number(getRouterParam(event, 'page')?.replace('.xml', '') || 1)
const urls = await $fetch<{ loc: string; lastmod: string }[]>(
`${useRuntimeConfig().apiBase}/seo/urls`, { query: { page } })
const base = 'https://www.yourstore.com'
const body = urls.map(u =>
`<url><loc>${base}${u.loc}</loc><lastmod>${u.lastmod}</lastmod></url>`).join('')
setHeader(event, 'content-type', 'application/xml; charset=utf-8')
return `<?xml version="1.0" encoding="UTF-8"?>` +
`<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${body}</urlset>`
}, { maxAge: 900, swr: true, getKey: e => getRouterParam(e, 'page') || '1' })
A sitemap.xml index route lists /sitemap/1.xml, /sitemap/2.xml and so on. Keep lastmod honest: use the content's real update time, not now(). Escape & in any URL that carries query strings. And make sure every URL in the sitemap is the canonical version, returns 200 and is indexable.
One canonical per page
Canonicals go wrong in three predictable ways: tracking parameters, sort and filter parameters, and trailing-slash or case variants. I normalise in one composable:
// composables/useCanonical.ts
const KEEP = new Set(['page']) // params that create a distinct page
export function useCanonical() {
const route = useRoute()
const base = 'https://www.yourstore.com'
const params = Object.entries(route.query)
.filter(([k]) => KEEP.has(k))
.sort(([a], [b]) => a.localeCompare(b))
const qs = new URLSearchParams(params as [string, string][]).toString()
const path = route.path.toLowerCase().replace(/\/+$/, '') || '/'
const href = `${base}${path}${qs ? `?${qs}` : ''}`
useHead({ link: [{ rel: 'canonical', href }] })
useSeoMeta({ ogUrl: href })
return href
}
Rules I agree with the content team up front: utm_*, gclid, sort and view toggles never appear in a canonical; real pagination does; filtered category pages are canonical only when we intend them to rank. When a site moves or a URL scheme changes, the canonical rules and the redirect map have to change together, which I covered in the replatforming redirect map playbook.
Image: AI-generated.
OG images as a cached endpoint
A link preview needs an absolute og:image URL that returns a real image, ideally 1200×630. I render it on the server from the page's title and a brand template, then cache it at the CDN:
// server/routes/og/[slug].png.ts
import { renderOgPng } from '~/server/utils/og' // wraps satori + resvg
export default defineCachedEventHandler(async (event) => {
const slug = getRouterParam(event, 'slug')!.replace('.png', '')
const product = await $fetch<{ name: string; price: string }>(
`${useRuntimeConfig().apiBase}/products/${slug}/og`).catch(() => null)
if (!product) {
return sendRedirect(event, '/og/default.png', 302) // never a HTML 404
}
setHeader(event, 'content-type', 'image/png')
setHeader(event, 'cache-control', 'public, max-age=86400, stale-while-revalidate=604800')
return renderOgPng({ title: product.name, subtitle: product.price })
}, { maxAge: 86400, getKey: e => getRouterParam(e, 'slug')! })
On the page: useSeoMeta({ ogImage: `https://www.yourstore.com/og/${slug}.png`, twitterCard: 'summary_large_image' }). Add a version or updated_at hash to the URL (/og/${slug}.png?v=1731650000) so a title change produces a fresh image instead of a cached old one. Social platforms cache previews on their side too, so the version parameter is what makes a re-share pick up the new image.
Cost and effort
For a typical catalog of 10,000–100,000 URLs, the work is small compared to the traffic it protects. These are my planning estimates for a team that already runs Nuxt and Laravel, not quotes:
| Item | Effort estimate | Ongoing cost driver |
|---|---|---|
| Paginated SEO URL endpoint + sitemap index | 1–2 days | Database reads, cached 15 min |
| Canonical composable + rules doc | 1 day | Review when routes change |
| OG image endpoint with template | 2–3 days | CPU per render, cached 24 h |
| CI checks for status, content type, canonical | 1 day | None |
Launch checklist
- [ ]
curl -sI /sitemap.xmlreturns200and an XML content type; every child sitemap stays under 50,000 URLs. - [ ] Every sitemap URL returns
200, is indexable and matches its own canonical. - [ ]
lastmodreflects real content updates. - [ ]
robots.txtlists the sitemap index URL. - [ ] Canonicals are absolute, lowercase, without tracking or sort parameters.
- [ ]
og:imageURLs are absolute, returnimage/pngorimage/jpeg, and nevertext/html. - [ ] Missing content falls back to a default OG image, not an error page.
- [ ] Cache headers are explicit and content updates purge or version the cached files.
- [ ] A CI job spot-checks 20 random URLs for all of the above.
Failure modes I see in production
- Sitemap lists non-canonical URLs. Search Console reports "Duplicate, Google chose different canonical than user" by the thousand.
-
Staging leaks. The sitemap is built from an environment variable that still points at
staging.on production. - OG endpoint behind auth or bot protection. Social crawlers get a challenge page and show no preview.
- Uncached image rendering. A viral share triggers thousands of renders and the API slows down for real users.
- Canonical set client-side only. In SPA mode the canonical is missing from the initial HTML that crawlers fetch.
FAQ
Should I use a Nuxt SEO module or write my own routes?
Use a module when your site is a standard content or catalog site; it handles chunking, indexes and defaults well. Write custom Nitro routes when you have multi-tenant domains, per-vendor catalogs or unusual URL rules the module cannot express cleanly.
How often should a dynamic sitemap refresh?
Cache it for 10–60 minutes with stale-while-revalidate, and purge on publish if your CDN supports it. Crawlers do not need second-by-second freshness, and the cache protects your database during crawl spikes.
Do filtered category pages need their own canonical?
Only if you want them to rank as distinct pages with unique content and demand. Otherwise point them to the unfiltered category canonical. Decide per filter with your SEO lead and encode the rule in one place.
What size should OG images be?
1200×630 pixels is the widely supported size for large link previews. Keep the file small, use PNG or JPEG, keep important text away from the edges, and always return an absolute HTTPS URL.
Why does my link preview still show the old image?
Social platforms cache previews independently of your CDN. Add a version parameter based on the content's update time to the og:image URL, then use each platform's debugging tool to re-scrape the page.
Can the Laravel backend generate the sitemap instead of Nuxt?
Yes. Many teams let Laravel write the XML and have Nuxt proxy or redirect /sitemap.xml to it. Keep a single source of URL rules either way, so the sitemap and canonical logic cannot drift apart.
Conclusion
Sitemaps, canonicals and OG images are three views of the same data: which pages exist, which URL is the real one and how each page looks when shared. Generate them from the backend at request time, cache them deliberately and test them in CI, and the SEO layer stops being something you fix after every release.
Follow & Connect
- LinkedIn: Loop Origin
- X: Muhammad Ali Mughal (@AliMughal887)
- GitHub: Loop Origin (@LoopOrigin)

Top comments (0)