预加载外部网站内容,然后重定向

时间:2022-08-24 16:50:02

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?

离开网站时,我的用户会收到您正在离开的消息,该消息会在4秒后重定向。是否可以通过某种方式预先加载目标网站的内容,以便在重定向后网站显示更快?

2 个解决方案

#1


5  

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

如果要获取的站点位于您的域中,您可以使用JavaScript解析下一个文件并请求资产。

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.

如果没有,你无法弄清楚它的资产(大多数情况下不是通过XHR),所以你无法预加载它们。您可以通过将网站放在隐藏的iframe中来破解它。您还可以将服务器用作代理,以获取资产列表并将其传递给HTML以开始预加载它们。

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.

尽管如此,这可能会带来很多努力。

#2


3  

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!)

我倾向于将这种预加载留给Web浏览器(和/或@alex显示的预取标记!)

#1


5  

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

如果要获取的站点位于您的域中,您可以使用JavaScript解析下一个文件并请求资产。

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.

如果没有,你无法弄清楚它的资产(大多数情况下不是通过XHR),所以你无法预加载它们。您可以通过将网站放在隐藏的iframe中来破解它。您还可以将服务器用作代理,以获取资产列表并将其传递给HTML以开始预加载它们。

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.

尽管如此,这可能会带来很多努力。

#2


3  

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!)

我倾向于将这种预加载留给Web浏览器(和/或@alex显示的预取标记!)