Skip to content

Ability to prevent preloading client-side scripts in next/document's Head #16853

Closed
@callumlocke

Description

@callumlocke

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 of Head.

  • Maybe the official Head could include some magic that automatically prevents link[rel=preload] elements being rendered if the parent Document doesn't also include a <NextScript />. That might sound a bit clever, but maybe it's the right approach logically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions