Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
950d67b7
Unverified
Commit
950d67b7
authored
Dec 14, 2019
by
Tim Neutkens
Committed by
GitHub
Dec 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add experiment for prefetching (#9747)
parent
838aec8f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
3 deletions
+10
-3
webpack-config.ts
packages/next/build/webpack-config.ts
+3
-0
page-loader.js
packages/next/client/page-loader.js
+7
-3
No files found.
packages/next/build/webpack-config.ts
View file @
950d67b7
...
@@ -677,6 +677,9 @@ export default async function getBaseWebpackConfig(
...
@@ -677,6 +677,9 @@ export default async function getBaseWebpackConfig(
'process.env.__NEXT_EXPORT_TRAILING_SLASH'
:
JSON
.
stringify
(
'process.env.__NEXT_EXPORT_TRAILING_SLASH'
:
JSON
.
stringify
(
config
.
exportTrailingSlash
config
.
exportTrailingSlash
),
),
'process.env.__NEXT_PREFETCH_PRELOAD'
:
JSON
.
stringify
(
config
.
experimental
.
prefetchPreload
),
'process.env.__NEXT_DEFER_SCRIPTS'
:
JSON
.
stringify
(
'process.env.__NEXT_DEFER_SCRIPTS'
:
JSON
.
stringify
(
config
.
experimental
.
deferScripts
config
.
experimental
.
deferScripts
),
),
...
...
packages/next/client/page-loader.js
View file @
950d67b7
/* global document, window */
/* global document, window */
import
mitt
from
'../next-server/lib/mitt'
import
mitt
from
'../next-server/lib/mitt'
const
prefetchOrPreload
=
process
.
env
.
__NEXT_PREFETCH_PRELOAD
?
'prefetch'
:
'preload'
function
supportsPreload
(
el
)
{
function
supportsPreload
(
el
)
{
try
{
try
{
return
el
.
relList
.
supports
(
'preload'
)
return
el
.
relList
.
supports
(
prefetchOrPreload
)
}
catch
{
}
catch
{
return
false
return
false
}
}
...
@@ -13,7 +17,7 @@ const hasPreload = supportsPreload(document.createElement('link'))
...
@@ -13,7 +17,7 @@ const hasPreload = supportsPreload(document.createElement('link'))
function
preloadLink
(
url
,
resourceType
)
{
function
preloadLink
(
url
,
resourceType
)
{
const
link
=
document
.
createElement
(
'link'
)
const
link
=
document
.
createElement
(
'link'
)
link
.
rel
=
'preload'
link
.
rel
=
prefetchOrPreload
link
.
crossOrigin
=
process
.
crossOrigin
link
.
crossOrigin
=
process
.
crossOrigin
link
.
href
=
url
link
.
href
=
url
link
.
as
=
resourceType
link
.
as
=
resourceType
...
@@ -217,7 +221,7 @@ export default class PageLoader {
...
@@ -217,7 +221,7 @@ export default class PageLoader {
// its own deduping mechanism.
// its own deduping mechanism.
if
(
if
(
document
.
querySelector
(
document
.
querySelector
(
`link[rel="
preload
"][href^="
${
url
}
"], script[data-next-page="
${
route
}
"]`
`link[rel="
${
prefetchOrPreload
}
"][href^="
${
url
}
"], script[data-next-page="
${
route
}
"]`
)
)
)
{
)
{
return
return
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment