dns-prefetch + 预连接 vs. 浏览器缓存 [英] dns-prefetch + preconnect vs. browser cache

查看:45
本文介绍了dns-prefetch + 预连接 vs. 浏览器缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了缩短页面加载时间,我想对外部 javascript 使用 dns-prefetchpreconnect.

To improve the page load time I want to use dns-prefetch and preconnect for external javascripts.

<link rel="dns-prefetch" href="https://example.com">
<link rel="preconnect" href="https://example.com">

如果资源(在我的例子中是外部 javascript)已经在浏览器缓存中会发生什么?dns-prefetchpreconnect 是否会不必要地增加页面加载时间?换句话说:dns-prefetchpreconnect 是否只在第一次页面加载时有用?

What happen if the ressource (in my case the external javascript) is already in the browser cache? Do dns-prefetch and preconnect add page load time unnecessarily? In other words: Are dns-prefetch and preconnect only useful on the first page load?

推荐答案

在重复访问时,如果所有资源都从缓存中获取,那么 preconnect/dns-prefetch 确实没有用.但它们不会增加页面加载时间.它们与页面加载并行发生,并且缓存读取不等待 DNS/TLC/TCP 解析.所以唯一的缺点是您创建了未使用的 TCP 连接并稍微增加了服务器的负载.

On the repeat visit, the preconnect/dns-prefetch will indeed be useless if all resources are taken from cache. But they will not increase page load time. They happen in parallel of page loading, and cache reads do not wait for DNS/TLC/TCP resolution. So the only drawback is that you create unused TCP connection and slightly increase the load on the server.

这篇关于dns-prefetch + 预连接 vs. 浏览器缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆