未验证 提交 1016b710 编写于 作者: T Tim Neutkens 提交者: GitHub

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
上级 c2a208d1
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册