Jordan Bos
Jordan Bos

Reputation: 47

Difference between the relative URLs "foo" and "./foo"?

When using relative URLs and want to address a file in the same folder we have two options:

I tried these and encountered the same results.

What's the difference between these two? Although the result is the same, is one preferred to another one?

Upvotes: 2

Views: 229

Answers (1)

amcgregor
amcgregor

Reputation: 1246

Essentially: there is none.

Both are relative to "the current context", called the base URI in the specification. (With ./ it's explicitly relative to the current context, without it, it's implicitly relative to the current context.) With links in both forms, the browser will perform relative resolution to determine the actual URL to navigate to.

Inclusion of such a prefix is essentially meaningless noise, given the implicit behaviour is explicitly documented, and the explicit form is optional. (It's not wrong, it's just not the optimal—most compact—form.)

Upvotes: 1

Related Questions