|
|
@ -73,32 +73,40 @@ export function usePrefetch() {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
rIC(() => {
|
|
|
|
rIC(() => {
|
|
|
|
document.querySelectorAll<HTMLAnchorElement>('#app a').forEach((link) => {
|
|
|
|
document
|
|
|
|
const { target, hostname, pathname } = link
|
|
|
|
.querySelectorAll<HTMLAnchorElement | SVGAElement>('#app a')
|
|
|
|
const extMatch = pathname.match(/\.\w+$/)
|
|
|
|
.forEach((link) => {
|
|
|
|
if (extMatch && extMatch[0] !== '.html') {
|
|
|
|
const { target } = link
|
|
|
|
return
|
|
|
|
const { hostname, pathname } = new URL(
|
|
|
|
}
|
|
|
|
link.href instanceof SVGAnimatedString
|
|
|
|
|
|
|
|
? link.href.animVal
|
|
|
|
|
|
|
|
: link.href,
|
|
|
|
|
|
|
|
link.baseURI
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
const extMatch = pathname.match(/\.\w+$/)
|
|
|
|
|
|
|
|
if (extMatch && extMatch[0] !== '.html') {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
// only prefetch same tab navigation, since a new tab will load
|
|
|
|
// only prefetch same tab navigation, since a new tab will load
|
|
|
|
// the lean js chunk instead.
|
|
|
|
// the lean js chunk instead.
|
|
|
|
target !== `_blank` &&
|
|
|
|
target !== `_blank` &&
|
|
|
|
// only prefetch inbound links
|
|
|
|
// only prefetch inbound links
|
|
|
|
hostname === location.hostname
|
|
|
|
hostname === location.hostname
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
if (pathname !== location.pathname) {
|
|
|
|
if (pathname !== location.pathname) {
|
|
|
|
observer!.observe(link)
|
|
|
|
observer!.observe(link)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// No need to prefetch chunk for the current page, but also mark
|
|
|
|
// No need to prefetch chunk for the current page, but also mark
|
|
|
|
// it as already fetched. This is because the initial page uses its
|
|
|
|
// it as already fetched. This is because the initial page uses its
|
|
|
|
// lean chunk, and if we don't mark it, navigation to another page
|
|
|
|
// lean chunk, and if we don't mark it, navigation to another page
|
|
|
|
// with a link back to the first page will fetch its full chunk
|
|
|
|
// with a link back to the first page will fetch its full chunk
|
|
|
|
// which isn't needed.
|
|
|
|
// which isn't needed.
|
|
|
|
hasFetched.add(pathname)
|
|
|
|
hasFetched.add(pathname)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|