Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preload external website content, then redirect

When leaving a website my user get a message you are now leaving, which redirects after 4 seconds. Can that time be used to somehow preload the target site's content, so that after the redirect the site appears faster?

like image 487
Moak Avatar asked Jan 21 '23 04:01

Moak


2 Answers

If the site to be fetched is on your domain, you can parse the next file with JavaScript and request the assets.

If not, you can't figure out its assets (not via XHR anyway, most of the time) so you can't preload them. You could hack it by placing the site in a hidden iframe. You could also use your server as a proxy, to get a list of assets and pass it to your HTML to start preloading them.

You could try also using this meta tag...

<link rel="prefetch" href="/images/big.jpeg">

Source.

It is a lot of effort for arguably not much gain though.

like image 52
alex Avatar answered Jan 24 '23 00:01

alex


You could start loading the site into an invisible <iframe>. If it's cached properly, this will reduce load time when the user actually enters the page.

This would however have all kinds of potential side effects, like autoplay music and videos starting in the background.

I would tend to leave this kind of preloading to the web browser (and/or the prefetch tag that @alex shows!)

like image 29
Pekka Avatar answered Jan 24 '23 02:01

Pekka