Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance: Absolute vs. Relative URLs

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 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?

like image 792
ma11hew28 Avatar asked Mar 01 '11 18:03

ma11hew28


People also ask

Are relative links faster than absolute?

Faster Load TimesPages that use relative URLs will load more quickly than pages that use absolute URLs, for the most part, although the difference is minuscule at best.

Are relative URLs faster?

Faster coding: Relative URLs. For faster and more effective coding, we recommend relative URLs. Rather than including the entire URL for each page you link, relative URLs cut down on the workload and time needed. For example, coding /about/ is much faster than https://www.example.com/about .

What is difference between absolute URL and relative URL?

An absolute URL contains all the information necessary to locate a resource. A relative URL locates a resource using an absolute URL as a starting point. In effect, the "complete URL" of the target is specified by concatenating the absolute and relative URLs.

What is the advantage of relative hyperlinking?

THE ADVANTAGES OF RELATIVE URLS The loading time is somewhat faster with the relative URL. However, this “something” is so minimal that it is of no further importance for the ranking. If you move your content or put it on another server for testing, this can be done quickly and easily with relative links.


1 Answers

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.

like image 181
Sripathi Krishnan Avatar answered Sep 23 '22 19:09

Sripathi Krishnan