Why would a developer place a forward slash at the start of each relative path?

It’s done in order to root the path (making it an absolute path).

It ensures that the path is not relative but read from the root of the site.

This allows one to move a file around and not have to change the links to the different resources.

Using your example:

src="https://stackoverflow.com/assets/js/jquery.js"

If the referencing file is in /pages/admin/main.html (for example) using relative paths you would use:

src="https://stackoverflow.com/questions/7613274/assets/js/jquery.js"

Suppose you move the file to a child directory. No changes would be needed for with the original rooted path, but the relative one would need to change to:

src="https://stackoverflow.com/questions/7613274/assets/js/jquery.js"

Leave a Comment