Are there any practical differences in the different URL types?
The other answers are very good.
I can only agree that any efficiency difference compared to the bandwidth used (number of bytes transferred) or performance will be minimal.
However, thinking in terms of portability (see ISO 9126 Quality of Software standard), I believe that systems should use Site root URLs to access your own resources (images, styles, scripts, etc.) and always avoid the protocol for external resources.
What I consider to be most important is to keep a pattern on URLs, and a pattern only exists if all URLs start with the meso prefix. This helps keep developers healthy and eliminates a lot of confusion, such as having to mentally calculate directories.
Is your application prepared to be secure?
Using absolutely absolute paths can lead to serious issues with sites that use HTTPS . The problem begins when your site is accessed via HTTPS and tries to include an HTTP (non-secure) resource.
For example, let's assume you want to include jQuery from a CDN :
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
However,ifyoursiteisaccessedviaHTTPS,thebrowserwillcomplainabouttheinsecure(HTTP)featureandwillnotloadthescript.Asaresult,Googleitselfindicatesthemostappropriateway:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
Note: According to this link , Internet Explorer in versions 7 and 8 will download it twice if you include a CSS with a non-protocol URL, but I did not test it.
A perfectly viable alternative is to always include external resources using HTTP
.
A personal experience
Regardless of the approach, not everything is flowers.
Some time ago I made a system using a Java framework that generated root URLs from the server, for example:
/application/style.css
However, when the application was installed in production, problems occurred because the company's branches used it under a reverse proxy and the root path would have to look like this:
/web/application/style.css
Would the solution simply add the /web
path to the URLs generated by the framework? No, because the company's headquarters accessed the system directly, without going through the reverse proxy. That is, the application served two different types of sources that accessed it by different URLs.
A possible solution would be to identify the source of the request or to look at the URL of the request and dynamically change the root of the generated URLs, but in that situation it was much simpler and more straightforward to use
../ style.css
This was possible because I developed the system so that all pages were on the same level: /home
, /usuarios
, /clientes
, etc.
But even if the system were not so, I could add the relative path programmatically, just as frameworks usually do by adding a base path to all URLs, right?
$ {basePath} / style.css
Here basePath
can be both the path relative to the site root and the path of the current page to the home directory where the style is.