Performance: Absolute vs. Relative URLs

后端 未结 5 505
感动是毒
感动是毒 2021-01-12 05:15

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

In his tutorial on how to style HTML5 elem

5条回答
  •  既然无缘
    2021-01-12 05:41

    The correct answer is - it depends.

    Hotlinking can be slow because -

    1. An extra DNS lookup is needed
    2. Unable to reuse an existing TCP/IP socket connection

    Hosting on your server can be slow because -

    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.

    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. You have too many resources (images/js) on your domain
    2. The other server is a CDN, and the resource is a popular enough so that there is a decent chance it will be present in the browser's cache. Think JQuery on google's servers.

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

提交回复
热议问题