All roads lead to preload
This commit is contained in:
parent
e0f35f5b53
commit
da8647fc29
1 changed files with 19 additions and 1 deletions
|
@ -39,7 +39,7 @@ function preloadinate() {
|
||||||
// TODO: this would ideally happen in the background (service worker)?
|
// TODO: this would ideally happen in the background (service worker)?
|
||||||
if (el.href.indexOf("#") == -1 && el.href.indexOf(".") == -1 && (el.href.startsWith("https://lyte.dev") || el.href.startsWith("http://localhost:1313"))) {
|
if (el.href.indexOf("#") == -1 && el.href.indexOf(".") == -1 && (el.href.startsWith("https://lyte.dev") || el.href.startsWith("http://localhost:1313"))) {
|
||||||
el.addEventListener("mouseover", (_ev) => putCache(el.href))
|
el.addEventListener("mouseover", (_ev) => putCache(el.href))
|
||||||
el.addEventListener("click", ev => {
|
el.addEventListener("click", async (ev) => {
|
||||||
if (el.href == window.location.href) {
|
if (el.href == window.location.href) {
|
||||||
ev.preventDefault()
|
ev.preventDefault()
|
||||||
return false
|
return false
|
||||||
|
@ -49,6 +49,24 @@ function preloadinate() {
|
||||||
history.replaceState(rep, "")
|
history.replaceState(rep, "")
|
||||||
console.log("replaceState: ", rep)
|
console.log("replaceState: ", rep)
|
||||||
if (!loadCache(el.href)) {
|
if (!loadCache(el.href)) {
|
||||||
|
window.location.href = el.href
|
||||||
|
window.location.reload()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
window.scrollTo(0, 0)
|
||||||
|
history.pushState([el.href, 0, 0], "", el.href)
|
||||||
|
preloadinate()
|
||||||
|
ev.preventDefault()
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
ev.preventDefault()
|
||||||
|
await putCache(el.href)
|
||||||
|
const rep = [window.location.href, window.scrollX, window.scrollY]
|
||||||
|
history.replaceState(rep, "")
|
||||||
|
console.log("replaceState: ", rep)
|
||||||
|
if (!loadCache(el.href)) {
|
||||||
|
window.location.href = el.href
|
||||||
|
window.location.reload()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
window.scrollTo(0, 0)
|
window.scrollTo(0, 0)
|
||||||
|
|
Loading…
Reference in a new issue