Prefetch and prerender all the sites
This commit is contained in:
parent
1a015f102c
commit
48f5730bbb
1 changed files with 26 additions and 0 deletions
|
|
@ -1,6 +1,32 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<script type="speculationrules">
|
||||
{"prefetch":[{"where":{"and":[{"href_matches":"/*"},{"not":{"href_matches":"/accounts/logout/"}}]}}],"prerender":[{"where":{"and":[{"href_matches":"/*"},{"not":{"href_matches":"/accounts/logout/"}}]},"eagerness":"eager"}]}
|
||||
</script>
|
||||
<script>
|
||||
if (!HTMLScriptElement.supports || !HTMLScriptElement.supports('speculationrules')) {
|
||||
const preloadedUrls = {};
|
||||
|
||||
function pointerenterHandler () {
|
||||
if (!preloadedUrls[this.href]) {
|
||||
preloadedUrls[this.href] = true;
|
||||
|
||||
const prefetcher = document.createElement('link');
|
||||
|
||||
prefetcher.as = prefetcher.relList.supports('prefetch') ? 'document' : 'fetch';
|
||||
prefetcher.rel = prefetcher.relList.supports('prefetch') ? 'prefetch' : 'preload';
|
||||
prefetcher.href = this.href;
|
||||
|
||||
document.head.appendChild(prefetcher);
|
||||
}
|
||||
}
|
||||
|
||||
document.querySelectorAll('a[href^="/"]').forEach(item => {
|
||||
item.addEventListener('pointerenter', pointerenterHandler);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue