DEV Community

Cover image for Relative and Absolute paths
robinwatson
robinwatson

Posted on

Relative and Absolute paths

This is my third post this week. I was prompted to start blogging about my learnings from Zell Liew's course in order to:

A) Help myself digest material and

B) Help others learn or re-learn a concept.

These posts are my own take on the material of the course and are intended to help solidify some JS and web dev concepts. Feel free to add some comments or better yet, correct me! Thanks!

Relative and Absolute paths

When I started to get into web dev someone told me that it was extremely important to understand the difference between relative and absolute paths. I started to overthink it a lot and many times got confused so maybe this analogy will help you understand if you've been struggling to figure it out:

Relative

Relative paths change. Imagine you walk to the bus stop, take the bus to work, walk to work and go upstairs to your office. Your path(home/walk1/bus/walk2/office/you) could have been different or may change in the future. It depends on your location but how you get there may always change. Maybe you get a drive one day: home/drive/work/you. I will say that when you have a larger code base, tracking down a file path can be tricky, which is why naming conventions and code structure is very important.

Absolute

Absolute paths can easily be thought of websites that you point your files to. The website rarely changes, for example font awesome or something if you are using a CDN. Maybe something behind the scenes on the websites end changed but from your file to the site, is a direct/absolute path.

Top comments (0)