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_ponents/jquery/dist/jquery.js"></script>
<script src="./bower_ponents/moment/min/moment-with-locales.js"></script>
<script src="./bower_ponents/elessar/dist/elessar.js"></script>
<script src="./bower_ponents/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_ponents/jquery/dist/jquery.js"></script>
should resolve into http://localhost:8081/develop/bower_ponents/jquery/dist/jquery.js
. That's obvious.
But it doesn't. Instead, they are being resolved into http://localhost:8081/bower_ponents/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_ponents/jquery/dist/jquery.js"></script>
also resolves into http://localhost:8081/bower_ponents/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?
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_ponents/jquery/dist/jquery.js"></script>
<script src="./bower_ponents/moment/min/moment-with-locales.js"></script>
<script src="./bower_ponents/elessar/dist/elessar.js"></script>
<script src="./bower_ponents/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_ponents/jquery/dist/jquery.js"></script>
should resolve into http://localhost:8081/develop/bower_ponents/jquery/dist/jquery.js
. That's obvious.
But it doesn't. Instead, they are being resolved into http://localhost:8081/bower_ponents/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_ponents/jquery/dist/jquery.js"></script>
also resolves into http://localhost:8081/bower_ponents/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?
Share Improve this question asked Sep 16, 2016 at 12:37 Bruno FingerBruno Finger 2,5833 gold badges29 silver badges50 bronze badges 5-
Can you share what's the DOCTYPE or could you try changing the DOCTYPE? If I am not wrong then
./
works with non-strict DOCTYPE. – Shubh Commented Sep 16, 2016 at 12:52 - It's has nothing to do with JS. Check your local server configuration... – Bozidar Sikanjic Commented Sep 16, 2016 at 12:58
-
@Shubh
<!DOCTYPE html>
– Bruno Finger Commented Sep 16, 2016 at 13:39 - 1 @BozidarSikanjic It has nothing to do with the server either. You can see in the screenshot attached that when I hover the mouse over the link, Chrome will show the URL it thinks it's the correct. – Bruno Finger Commented Sep 16, 2016 at 13:40
- stackoverflow./questions/24028561/relative-path-in-html – Bozidar Sikanjic Commented Sep 17, 2016 at 19:40
1 Answer
Reset to default 15Reason can be tag <base href="/">
in the head section.