How to Preload a Page Before Redirect to Avoid Latency
Hello, I’m working on a website and ran into a problem. I have a button that redirects to another page, but it’s not a standard link. I handle the redirect using:
window.location.href = "http://page";
I do this because I want to show an animation before the redirect, like this:
button.addEventListener("click", () => {
anim.classList.add("animClass");
setTimeout(() => {
window.location.href = "http://page";
}, 1000);
});
However, this approach isn’t very clean and has several issues. The main problem is that I can’t predict the user’s network speed, so there might be noticeable latency.
I was wondering if it’s possible to do something like this: preload the page in the background, cache it, and then when the user clicks the button, redirect them instantly. This way, there would be no delay.