The links on your site come in the form of Absolute URLs and Relative URLs, and are used to point to different pages and content on your site. This article discusses the difference between them and where best to use them!
How Absolute URLs and Relative URLs work
- An absolute URL contains all the information necessary to locate a resource. In context to the Cart.com online stores system it begins with https://.
- For example, https://cart.com is an absolute URL.
- A relative URL typically contains only the path to a specific file. In context to the Cart.com online stores system, these typically begin with a forward slash. The forward slash tells the browser to go to the domain of the site and look for a file.
- The benefit of using Relative URLs is if your domain changes you don’t have to manually update all of your site links.
- For example, /images/img.jpg is telling the browser to go to the domain, then look for the images folder, then find the img.jpg file inside the images folder. If you update your domain your /images/img.jpg link does not need to be updated.
How Absolute URLs and Relative URLs are used
- Used for your domain URL, <base href="http://cart.com/">
- Used to link to external sites, <a href="http://othersite.com"></a>
- Used to link to internal site content,<a href="/images/profilepicture.png">Link Text</a>