Replies: 3 comments 3 replies
-
You can use a custom in the {isFullyStaticPage ? <StaticHead /> : <Head />}
<body>
<Main />
{!isFullyStaticPage && <NextScript />}
</body> And the StaticHead implementation: import { Head } from 'next/document'
/**
* Remove all JavaScript from the document (convert to 100%
* static page)
*/
export default class StaticHead extends Head {
render() {
const res = super.render()
function transform(node) {
// remove all link preloads
if (
node &&
node.type === 'link' &&
node.props &&
node.props.rel === 'preload'
) {
return null
}
if (node && node.props && node.props.children) {
return {
...node,
props: {
...node.props,
children: Array.isArray(node.props.children)
? node.props.children.map(transform)
: transform(node.props.children),
},
}
}
if (Array.isArray(node)) {
return node.map(transform)
}
return node
}
return transform(res)
}
} |
Beta Was this translation helpful? Give feedback.
-
Interesting! I've used this plugin to achieve the same thing in Gatsby, I think it can be worth exploring for static sites where performance is critical. |
Beta Was this translation helpful? Give feedback.
-
Hello @Mirodil . Yes, this is possible and fully supported inside Next.js with a feature called |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I could not find in the documentation how to rid of js file content during the static site build. Is it possible to export pure HTML files during static site generation?
Thank you,
Beta Was this translation helpful? Give feedback.
All reactions