20
loading...
This website collects cookies to deliver better user experience
https://breakfast.club
), wait for the server to get back to you (loading spinner), then enjoy your "meal" once it's ready (the page is done loading! 🎉)<link rel="stylesheet" href="documentation.css">
. When you click another link that also pulls this CSS, the browser's smart enough to say "oh, I loaded this already! I'll just use that and apply it to the page." The same goes for images and fonts as well.https://spa-breakfast.club
)<a href="/desert">Go eat desert</a>
<script>
document.addEventListener('click', (event) => {
if (
// if you clicked on an A-nchor tag (link)
event.target.tagName === 'A' &&
// and you're going to a page on this domain (like /desert)
event.target.origin === location.origin
) {
// don't ask the server for that resource!
event.preventDefault()
// instead, we'll go fetch the resource ourselves
const response = fetch('https://buffet.table/desert')
// ...convert that response to something we can work with
const htmlString = await response.text()
const desert = new DOMParser()
.parseFromString(htmlString, 'text/html')
// ...and do something with that desert element
// ex. append desert to our "plate" in the DOM
document.querySelector('.my-plate').appendChild(desert)
}
})
</script>
fetch
API native to all modern browsers as demo-d above./medium-rare-burger
to /well-done-burger
.