diff --git a/packages/next/next-server/server/next-server.ts b/packages/next/next-server/server/next-server.ts index 3f928b43a73fb..7a960f12c039a 100644 --- a/packages/next/next-server/server/next-server.ts +++ b/packages/next/next-server/server/next-server.ts @@ -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, @@ -242,6 +242,17 @@ export default class Server { this.pagesManifest = require(pagesManifestPath) } + // Pages pre-import speed up initial pages render + if (this.pagesManifest) { + 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)