Home > Back-end >  Failed to load resource: the server responded with a status of 404 () - couldn't recognize css
Failed to load resource: the server responded with a status of 404 () - couldn't recognize css

Time:06-07

Getting page live on GitHub.

this was when it didn't work:

<link rel="stylesheet" href="/style.css">
<script defer src="/script.js"></script>

this is now, when it works:

    <link rel="stylesheet" href="style.css">
    <script defer src="script.js"></script>

What is the difference? Isn't that the same?

CodePudding user response:

Not exactly. the / in the script.js tells where to find the file. / is telling it the "root" of the file system, while script.js is telling it relative to this file and "beside" it.

CodePudding user response:

If your html/css/js files are in the same folder, that doesn't mean that / is pointing to that folder.

What you can do is find out where it points to and use that in your link and script tags. For example:

<link rel="stylesheet" href="/public/style.css">
<script defer src="/public/script.js"></script>

Passing relative addresses might become problematic in the future. Specially if you use routing in your application.

  • Related