Description
Feature request
Is your feature request related to a problem? Please describe.
Occasionally, I want to omit all client-side JavaScript on certain pages. I still want to be able to use JSX components to render the HTML (either via static export or SSR), but I don't want to hydrate the app on the client at all.
So I write a custom Document
that conditionally omits the <NextScript />
element for certain pages.
But when I do this, the default <Head />
still renders various <link rel="preload">
links for various JS files. So the scripts are still downloaded even though they are never executed, wasting bandwidth.
Describe the solution you'd like
The ability to disable preload links by setting a prop on the Head
component from next/document
.
Describe alternatives you've considered
-
I could omit the
<Head />
entirely and write my own<head>...</head>
, omitting preload link elements, but that would mean losing the other functionality ofHead
. -
Maybe the official
Head
could include some magic that automatically preventslink[rel=preload]
elements being rendered if the parentDocument
doesn't also include a<NextScript />
. That might sound a bit clever, but maybe it's the right approach logically.