Reputation: 3748
<file_name>
<a href="file.html">link</a>
<slash><file_name>
<a href="/file.html">link</a>
<dot+slash><file_name>
<a href="./file.html">link</a>
Which of these is recommended/preferred?
Do any of them impact the speed of retrieval?
What are the pros and cons when using either of them?
There's an extensive article on URLs by skorks here: What Every Developer Should Know About URLs, but it does not give answers to any of my questions.
Upvotes: 0
Views: 107
Reputation: 88
There's no reasonable difference between them in terms of speed/retrival.
- First and third are the same case: the resource named file.html resides in the same directory of the current file.
- In the second option "/file.html" means the file is located in the webroot of your application.
Here is explained w3school
Upvotes: 1
Reputation: 51634
Option 1 and 3 produce the exact same HTTP GET request. Option 2 is different because a path starting with /
will try to retrieve the file from the root rather than the current path.
Upvotes: 1
Reputation: 324640
Number 2 is NOT the same as the others, because it resolves to the root of the website and not the current folder.
This question sounds suspiciously like micro-optimization to me, and the answer is fairly simple: The browser resolves the paths when a link is encountered, using the current URL or the <base href="..." />
if one is provided. Therefore there is absolutely no difference.
Upvotes: 1
Reputation: 499002
There is no specific recommendation.
The retrieval speed has no bearing on how the URI is constructed.
The only thing that you need to consider is whether the linking page and the page you are linking to are part of a group of pages - if you move them together then if your links are in style 2 they will break. If file.html
will always be on the root of the site, then moving this file will make no difference.
I don't see the point of style 3.
Upvotes: 1