mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Don’t prefetch on slow network / when datasaver is enabled (#5876)
Inspired by https://twitter.com/addyosmani/status/1073118564423356416 I've made the checking function slightly smaller (including both conditions on one line makes Terser optimize the condition). cc @addyosmani
This commit is contained in:
parent
c2a208d141
commit
1016b71011
|
@ -132,6 +132,14 @@ export default class PageLoader {
|
|||
}
|
||||
this.prefetchCache.add(scriptRoute)
|
||||
|
||||
// Inspired by quicklink, license: https://github.com/GoogleChromeLabs/quicklink/blob/master/LICENSE
|
||||
// Don't prefetch if the user is on 2G / Don't prefetch if Save-Data is enabled
|
||||
if ('connection' in navigator) {
|
||||
if ((navigator.connection.effectiveType || '').indexOf('2g') !== -1 || navigator.connection.saveData) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Feature detection is used to see if preload is supported
|
||||
// If not fall back to loading script tags before the page is loaded
|
||||
// https://caniuse.com/#feat=link-rel-preload
|
||||
|
|
Loading…
Reference in a new issue