Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental per-page option to disable JS preloads (#21329)
As discussed with @csswizardry. This is a temporary option in case you know the preloads are not needed. It will likely be a default once the ScriptLoader work from @janicklas-ralph has been proven in partner apps and landed. ```js // pages/index.js export const config = { unstable_JsPreload: false } ```
- Loading branch information
1 parent
1190043
commit 56b149f
Showing
7 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
onDemandEntries: { | ||
// Make sure entries are not getting disposed. | ||
maxInactiveAge: 1000 * 60 * 60, | ||
}, | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const config = { | ||
unstable_JsPreload: false, | ||
} | ||
|
||
export default () => <h1>Hello World!</h1> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* eslint-env jest */ | ||
|
||
import { join } from 'path' | ||
import cheerio from 'cheerio' | ||
import { | ||
nextServer, | ||
nextBuild, | ||
startApp, | ||
stopApp, | ||
renderViaHTTP, | ||
findPort, | ||
launchApp, | ||
killApp, | ||
} from 'next-test-utils' | ||
|
||
const appDir = join(__dirname, '../') | ||
let appPort | ||
let server | ||
let app | ||
jest.setTimeout(1000 * 60 * 5) | ||
|
||
const context = {} | ||
|
||
describe('disabled JS preloads', () => { | ||
describe('production mode', () => { | ||
beforeAll(async () => { | ||
await nextBuild(appDir) | ||
app = nextServer({ | ||
dir: join(__dirname, '../'), | ||
dev: false, | ||
quiet: true, | ||
}) | ||
|
||
server = await startApp(app) | ||
context.appPort = appPort = server.address().port | ||
}) | ||
afterAll(() => stopApp(server)) | ||
|
||
it('should render the page', async () => { | ||
const html = await renderViaHTTP(appPort, '/') | ||
expect(html).toMatch(/Hello World/) | ||
}) | ||
|
||
it('should not have JS preload links', async () => { | ||
const html = await renderViaHTTP(appPort, '/') | ||
const $ = cheerio.load(html) | ||
expect($('link[rel=preload]').length).toBe(0) | ||
}) | ||
}) | ||
|
||
describe('dev mode', () => { | ||
let appPort | ||
let app | ||
|
||
beforeAll(async () => { | ||
appPort = await findPort() | ||
app = await launchApp(join(__dirname, '../'), appPort) | ||
}) | ||
|
||
afterAll(() => killApp(app)) | ||
|
||
it('should render the page', async () => { | ||
const html = await renderViaHTTP(appPort, '/') | ||
expect(html).toMatch(/Hello World/) | ||
}) | ||
|
||
it('should not have JS preload links', async () => { | ||
const html = await renderViaHTTP(appPort, '/') | ||
const $ = cheerio.load(html) | ||
expect($('link[rel=preload]').length).toBe(0) | ||
}) | ||
}) | ||
}) |