Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up initial page render #23196

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/next/next-server/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs'
import chalk from 'chalk'
import { IncomingMessage, ServerResponse } from 'http'
import Proxy from 'next/dist/compiled/http-proxy'
import { join, relative, resolve, sep } from 'path'
import { join, relative, resolve, sep, extname } from 'path'
import {
parse as parseQs,
stringify as stringifyQs,
Expand Down Expand Up @@ -242,6 +242,21 @@ export default class Server {
this.pagesManifest = require(pagesManifestPath)
}

// Pages pre-import speed up initial pages render
if (this.pagesManifest && !this._isLikeServerless) {
[
this.pagesManifest['/_document'],
this.pagesManifest['/_app'],
...Object.values(this.pagesManifest),
].forEach((pageModule) => {
if (extname(pageModule) !== '.js') {
return
}

require(join(this.serverBuildDir, pageModule))
})
}

this.customRoutes = this.getCustomRoutes()
this.router = new Router(this.generateRoutes())
this.setAssetPrefix(assetPrefix)
Expand Down