性能:绝对与相对URL [英] Performance: Absolute vs. Relative URLs

查看:160
本文介绍了性能:绝对与相对URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么更快? 热链接(内联链接)绝对URI 或自己承载资源并使用相对URI

What's faster? Hot linking (inline linking) to an absolute URI or hosting the resource yourself and using a relative URI?

在他的教程,Remy Sharp指出热链接会导致额外的HTTP [GET]请求。我同意你是否将热链接与复制&将脚本粘贴(嵌入)到HTML中。但是,如果您将热链接与本地托管脚本进行比较并通过相对路径进行链接,那么我认为热链接实际上(从未如此轻微)更快,因为浏览器不必解析绝对来自相对路径的URL。但是,在这两种情况下,都会执行额外的HTTP GET请求,对吗?

In his tutorial on how to style HTML5 elements in Internet Explorer, Remy Sharp states that hot linking causes an "extra HTTP [GET] request." I agree if you're comparing hot linking to copying & pasting (embedding) the script into the HTML. But, if you're comparing hot linking to hosting the script locally and linking via a relative path, then I'd argue that hot linking is actually (ever-so-slightly) faster because the browser doesn't have to resolve the absolute URL from the relative path. In both cases, however, an extra HTTP GET request is performed, correct?

推荐答案

正确的答案是 - 这取决于。

The correct answer is - it depends.

热链接可能很慢,因为 -

Hotlinking can be slow because -


  1. 需要额外的DNS查找

  2. 无法重用现有的TCP / IP套接字连接

服务器上的托管可能很慢因为 -

Hosting on your server can be slow because -


  1. 浏览器每个主机只允许n个并发请求。再向同一主机发出一个请求有可能引入排队,这可能很慢。数字'n'是浏览器特定的,介于2到6之间。请参阅browserscope>网络>每个主机名的连接

  1. Browsers only allow n concurrent requests per host. Having one more request to the same host has the potential to introduce queuing, which can be slow. The number 'n' is browser specific, and is anywhere between 2 and 6. See browserscope > network > connections per host name.

如果你认为两台服务器在各方面都相同,我会说服务器上的托管速度会更快。在每个主机的连接数为6的新浏览器中尤其如此。

If you assume both servers are identical in every respect, I'd say hosting on your server is going to be faster. This is true especially on new browsers where the number of connections per host is 6.

但遗憾的是,事情从未如此简单。我建议仅在以下情况下使用热链接 -

But sadly, things are never so simple. I'd recommend using hotlinking only if -


  1. 您的域名资源太多(图片/ js)

  2. 另一台服务器是CDN,资源非常流行,因此浏览器的缓存中存在很大的机会。在谷歌的服务器上思考JQuery。

对于所有其他用例,最好在自己的服务器上托管。

For all other use cases, you are better off hosting on your own servers.

这篇关于性能:绝对与相对URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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