Last active
March 10, 2021 09:27
-
-
Save alinzk/c383c5ebaf4b17329743a8e1707156ed to your computer and use it in GitHub Desktop.
Customized Head from next.js to disable preloading JS and CSS assets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
NOTE: This modifies next.js internal api behavior and may break your application. | |
Tested on next.js version: 9.2.1 | |
*/ | |
import React from 'react'; | |
import { Head } from 'next/document'; | |
class HeadCustom extends Head { | |
// https://github.com/zeit/next.js/blob/d467e040d51ce1f8d2bf050d729677b6dd99cb96/packages/next/pages/_document.tsx#L187 | |
getCssLinks() { | |
const { assetPrefix, files } = this.context._documentProps; | |
const cssFiles = files && files.length ? files.filter(f => /\.css$/.test(f)) : []; | |
const cssLinkElements = []; | |
cssFiles.forEach((file) => { | |
cssLinkElements.push( | |
<link | |
key={file} | |
nonce={this.props.nonce} | |
rel="stylesheet" | |
href={`${assetPrefix}/_next/${encodeURI(file)}`} | |
crossOrigin={this.props.crossOrigin || (process: any).crossOrigin} | |
/> | |
); | |
}); | |
return cssLinkElements.length === 0 ? null : cssLinkElements; | |
} | |
getPreloadMainLinks() { | |
return []; | |
} | |
getPreloadDynamicChunks() { | |
return []; | |
} | |
} | |
export default HeadCustom; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment