mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Make initial HTML smaller (#5183)
This commit is contained in:
parent
e2d331dbcc
commit
a912a4d9dd
|
@ -49,8 +49,8 @@ envConfig.setConfig({
|
||||||
const asPath = getURL()
|
const asPath = getURL()
|
||||||
|
|
||||||
const pageLoader = new PageLoader(buildId, prefix)
|
const pageLoader = new PageLoader(buildId, prefix)
|
||||||
window.__NEXT_LOADED_PAGES__.forEach(({ route, fn }) => {
|
window.__NEXT_LOADED_PAGES__.forEach(([r, f]) => {
|
||||||
pageLoader.registerPage(route, fn)
|
pageLoader.registerPage(r, f)
|
||||||
})
|
})
|
||||||
delete window.__NEXT_LOADED_PAGES__
|
delete window.__NEXT_LOADED_PAGES__
|
||||||
window.__NEXT_REGISTER_PAGE = pageLoader.registerPage.bind(pageLoader)
|
window.__NEXT_REGISTER_PAGE = pageLoader.registerPage.bind(pageLoader)
|
||||||
|
|
|
@ -178,22 +178,7 @@ export class NextScript extends Component {
|
||||||
static getInlineScriptSource (documentProps) {
|
static getInlineScriptSource (documentProps) {
|
||||||
const { __NEXT_DATA__ } = documentProps
|
const { __NEXT_DATA__ } = documentProps
|
||||||
const { page, pathname } = __NEXT_DATA__
|
const { page, pathname } = __NEXT_DATA__
|
||||||
|
return `__NEXT_DATA__ = ${htmlescape(__NEXT_DATA__)};__NEXT_LOADED_PAGES__=[];__NEXT_REGISTER_PAGE=function(r,f){__NEXT_LOADED_PAGES__.push([r, f])}${page === '/_error' ? `;__NEXT_REGISTER_PAGE(${htmlescape(pathname)},function(){var e = new Error('Page does not exist: ${htmlescape(pathname)}');e.statusCode=404;return {error:e}})`:''}`
|
||||||
return `
|
|
||||||
__NEXT_DATA__ = ${htmlescape(__NEXT_DATA__)}
|
|
||||||
__NEXT_LOADED_PAGES__ = []
|
|
||||||
|
|
||||||
__NEXT_REGISTER_PAGE = function (route, fn) {
|
|
||||||
__NEXT_LOADED_PAGES__.push({ route: route, fn: fn })
|
|
||||||
}${page === '_error' ? `
|
|
||||||
|
|
||||||
__NEXT_REGISTER_PAGE(${htmlescape(pathname)}, function() {
|
|
||||||
var error = new Error('Page does not exist: ${htmlescape(pathname)}')
|
|
||||||
error.statusCode = 404
|
|
||||||
|
|
||||||
return { error: error }
|
|
||||||
})`: ''}
|
|
||||||
`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
|
|
Loading…
Reference in a new issue