Inline Minification
Nuxt SEO Utils automatically minifies inline <script> and <style> tags at build time. Runtime minification is opt-in.
How It Works
The module provides two complementary minification modes that can be toggled independently.
Build Mode
At build time, the module has access to native tooling for full minification:
- JavaScript: Minified with Rolldown (Vite 8+) or esbuild (Vite 7), automatically detected
- CSS: Minified with lightningcss (full CSS optimization)
This applies to:
- Static scripts and styles defined in
app.headwithin yournuxt.config - JSON scripts and inline styles in prerendered/generated route HTML
Runtime Mode
For dynamic SSR where scripts are generated per request (hydration payloads, useHead() injections), the module registers an Unhead ssr:render plugin that minifies HeadTag content before it's serialized to HTML.
Runtime mode compacts JSON scripts and inline CSS. It preserves JavaScript, import maps, speculation rules, and custom script types.
JavaScript minification needs a parser. The module runs parser-based JavaScript minification only at build time.
Build mode uses parser-based minifiers and has no runtime cost. Runtime mode adds work to every SSR request. Enable it only after measuring the transfer savings and CPU cost for your application.
Configuration
Build mode is enabled by default. You can configure both modes in your nuxt.config:
export default defineNuxtConfig({
seo: {
minify: { build: true, runtime: false },
},
})export default defineNuxtConfig({
seo: {
minify: true,
},
})export default defineNuxtConfig({
seo: {
minify: { runtime: true, build: false },
},
})export default defineNuxtConfig({
seo: {
minify: false,
},
})What Gets Minified
| Content | Build Mode | Runtime Mode |
|---|---|---|
app.head scripts/styles | Rolldown or esbuild / lightningcss | n/a (static) |
| Prerendered route HTML | JSON / lightweight CSS | n/a (static) |
| Dynamic JavaScript | Preserved | Preserved |
useHead() JSON scripts | JSON | JSON |
useHead() injected styles | n/a (dynamic) | Lightweight CSS |
What Gets Skipped
The following are skipped by the JS minifier:
- JSON script types (
application/ld+json,application/json) are minified viaJSON.parse/JSON.stringifyinstead of JS minification importmapandspeculationrulesscript types are left completely untouched- External scripts (with
srcattribute) - Custom script types are preserved at build time and runtime
- Dynamic JavaScript is preserved during SSR and prerendering