Skip to content

Instantly share code, notes, and snippets.

@robbie01
Last active March 30, 2017 19:44
Show Gist options
  • Save robbie01/195cc3e8c6fda3a92094d3d18ddbc672 to your computer and use it in GitHub Desktop.
Save robbie01/195cc3e8c6fda3a92094d3d18ddbc672 to your computer and use it in GitHub Desktop.
Reload the page without reloading the page (uses Fetch API and ES6)
fetch(window.location.href).then(res =>
res.text().then(text => {
let domParser = new DOMParser()
let newDoc = domParser.parseFromString(text, res.headers.get('Content-Type').split(';')[0])
let newNode = document.importNode(newDoc.documentElement, true)
document.replaceChild(newNode, document.documentElement)
})
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment