-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprerender.js
More file actions
30 lines (27 loc) · 888 Bytes
/
prerender.js
File metadata and controls
30 lines (27 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const targetPage = 'music.html';
if (
HTMLScriptElement.supports &&
HTMLScriptElement.supports('speculationrules')
) {
console.log('The browser supports the Speculation Rules API.');
const specScript = document.createElement('script');
specScript.type = 'speculationrules';
const specRules = {
prerender: [{
where: {
and: [
{ href_matches: targetPage },
{ not: { selector_matches: '[rel~=nofollow]' } }
]
}
}]
};
specScript.textContent = JSON.stringify(specRules);
document.head.append(specScript);
} else {
console.log('The browser not supports the Speculation Rules API.');
const linkElem = document.createElement('link');
linkElem.rel = 'prefetch';
linkElem.href = '/music.html';
document.head.append(linkElem);
}