diff --git a/docs/2.guide/1.concepts/3.rendering.md b/docs/2.guide/1.concepts/3.rendering.md index cc8503fb10..af31e52a73 100644 --- a/docs/2.guide/1.concepts/3.rendering.md +++ b/docs/2.guide/1.concepts/3.rendering.md @@ -100,6 +100,7 @@ Nuxt 3 includes route rules and hybrid rendering support. Using route rules you - `swr` - Add cache headers to the server response and cache it in the server or reverse proxy for a configurable TTL. The `node-server` preset of Nitro is able to cache the full response. For Netlify and Vercel, the response is also added to the CDN layer. - `static` - The behavior is the same as `swr` except that there is no TTL; the response is cached until the next deployment. On Netlify and Vercel, it enables full incremental static generation. - `prerender` - Prerenders routes at build time and includes them in your build as static assets +- `experimentalNoScripts` - Disables rendering of Nuxt scripts and JS resource hints for sections of your site. **Examples:** diff --git a/packages/nuxt/src/core/runtime/nitro/renderer.ts b/packages/nuxt/src/core/runtime/nitro/renderer.ts index 78ed13c2e3..86dd6acf1d 100644 --- a/packages/nuxt/src/core/runtime/nitro/renderer.ts +++ b/packages/nuxt/src/core/runtime/nitro/renderer.ts @@ -276,6 +276,8 @@ export default defineRenderHandler(async (event) => { ? await renderInlineStyles(ssrContext.modules ?? ssrContext._registeredComponents ?? []) : '' + const NO_SCRIPTS = process.env.NUXT_NO_SCRIPTS || routeOptions.experimentalNoScripts + // Create render context const htmlContext: NuxtRenderHTMLContext = { island: Boolean(islandContext), @@ -285,7 +287,7 @@ export default defineRenderHandler(async (event) => { process.env.NUXT_JSON_PAYLOADS ? _PAYLOAD_EXTRACTION ? `` : null : _PAYLOAD_EXTRACTION ? `` : null, - _rendered.renderResourceHints(), + NO_SCRIPTS ? null : _rendered.renderResourceHints(), _rendered.renderStyles(), inlinedStyles, ssrContext.styles @@ -297,7 +299,7 @@ export default defineRenderHandler(async (event) => { ]), body: [_rendered.html], bodyAppend: normalizeChunks([ - process.env.NUXT_NO_SCRIPTS + NO_SCRIPTS ? undefined : (_PAYLOAD_EXTRACTION ? process.env.NUXT_JSON_PAYLOADS @@ -307,7 +309,7 @@ export default defineRenderHandler(async (event) => { ? renderPayloadJsonScript({ id: '__NUXT_DATA__', ssrContext, data: ssrContext.payload }) : renderPayloadScript({ ssrContext, data: ssrContext.payload }) ), - _rendered.renderScripts(), + routeOptions.experimentalNoScripts ? undefined : _rendered.renderScripts(), // Note: bodyScripts may contain tags other than