I have a document located at http://localhost:8081/develop
.
The index.html
, located at http://localhost:8081/develop/index.html
contains the following:
<html>
<head>
...
<link rel="stylesheet" href="./styles.min.css">
<script src="./bower_components/jquery/dist/jquery.js"></script>
<script src="./bower_components/moment/min/moment-with-locales.js"></script>
<script src="./bower_components/elessar/dist/elessar.js"></script>
<script src="./bower_components/EventSource/eventsource.js"></script>
...
</head>
<body>
...
</body>
</html>
ALL of the files starts with a ./
, telling the browser that it should search them in the current directory, for example: <script src="./bower_components/jquery/dist/jquery.js"></script>
should resolve into http://localhost:8081/develop/bower_components/jquery/dist/jquery.js
. That's obvious.
But it doesn't. Instead, they are being resolved into http://localhost:8081/bower_components/jquery/dist/jquery.js
, throwing tons of errors in the console.
The same thing will happen if instead of using ./
in the beginning of the files, I'd remove the first slash: <script src="bower_components/jquery/dist/jquery.js"></script>
also resolves into http://localhost:8081/bower_components/jquery/dist/jquery.js
.
It feels like a very basic question but I really need that those files have relative paths and that those paths works as expected. So why aren't them?
A relative URL is a URL that only includes the path. The path is everything that comes after the domain, including the directory and slug. Because relative URLs don't include the entire URL structure, it is assumed that when linking a relative URL, it uses the same protocol, subdomain and domain as the page it's on.
To link pages using relative URL in HTML, use the <a> tag with href attribute. Relative URL is used to add a link to a page on the website. For example, /contact, /about_team, etc.
Relative File Path: It describes the path of the file relative to the location of the current web page file. Example 1: It shows the path of the file present in the same folder of the current web page file.
Reason can be tag <base href="/">
in the head section.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With