Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialArwin Goo
Courses Plus Student 356 PointsRelative vs Absolute links
Hi guys, I'm not sure I understand why relative link should be used ahead of absolute links. I didn't get the part where absolute links would break if the website was placed on another domain. Can anyone clarify? Thanks!
4 Answers
naz
857 PointsSay for example you build you website and upload to the domain www.arwingoo1.com, there is an image on the home page page that uses an absolute link like, http://ww.arwingoo1.com/images/image1.jpg] to display the image. It work fine, great no problem.
But what if you change your mind a week later and decide you no longer want to use the domain ww.arwingoo1.com but would rather use gooarwin1.com, well now when you upload the website that image will still have a reference to the old location. In fact all images, link etc will have a reference to the old location and won't work, you will need to change them all.
But if you had used a relative reference like /image/image1.jpg then no matter where you upload the site it will simply look for a directory called images on that domain and pull the image from there.
Chris Wise
1,501 PointsIf you point to a relative link you can take your whole project and move it because it is all self contained. If they are absolute links, they all contain a specific domain and you would have to go back and re-point all of your images as their location would change.
Mireille Pasos
35,469 PointsHi,
I'll give you a quick example: let's say you work for a large company that has a large website called "www.myebsite.com" and within it you have several pages you want to link to: "www.mywebsite.com/about", "www.mywebsite.com/contact", etc and for some reason, let's say your company needs to move your site to a different domain called "www.mysupernewwebsite.com" but you have dozens if not hundreds of pages and links to them... imagine having to go through all of them and having to change the links one by one. Whereas if you have your links as "/contact", "/about", etc... you don't need to do anything, they will keep pointing to the right pages.
I hope this helps.
P.S. It happened to me with the first website I ever managed and it was a nightmare.
Arwin Goo
Courses Plus Student 356 PointsThanks Nazim, Mireille and Chris! Totally get it now. Appreciate the help :)