Skip to content

Instantly share code, notes, and snippets.

@aaronpeters
Last active May 27, 2024 08:11
Show Gist options
  • Save aaronpeters/1701090f36caf3f71009ff7e9576a5d0 to your computer and use it in GitHub Desktop.
Save aaronpeters/1701090f36caf3f71009ff7e9576a5d0 to your computer and use it in GitHub Desktop.
Speculation Rules Suitable
if (
HTMLScriptElement.supports &&
HTMLScriptElement.supports("speculationrules")
) {
const specScript = document.createElement("script");
specScript.type = "speculationrules";
specRules = {
prefetch: [
{
where: {
and: [
{
href_matches: "/*",
},
{
not: {
href_matches: "/logout",
}
}
]
},
eagerness: "moderate"
}
]
};
specScript.textContent = JSON.stringify(specRules);
document.body.append(specScript);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment