Created
August 5, 2019 19:21
-
-
Save jcuffe/7addcf46752f335260a3031826135ce2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class APrefetch extends HTMLAnchorElement { | |
constructor() { | |
super() | |
} | |
connectedCallback() { | |
this.addEventListener("click", event => { | |
event.preventDefault() | |
const xhr = new XMLHttpRequest() | |
// Replace elements within the router | |
xhr.addEventListener("load", function() { | |
const incoming = this.responseXML.querySelector("body") | |
const router = document.querySelector("body") | |
router.innerHTML = incoming.innerHTML | |
}) | |
xhr.open("GET", this.href) | |
// Parse the document as XML | |
xhr.responseType = "document" | |
xhr.send() | |
}) | |
} | |
} | |
window.customElements.define("a-prefetch", APrefetch, { extends: "a" }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment