Register now or log in to join your professional community.
In general, it is considered best-practice to use relative URLs, so that your website will not be bound to the base URL of where it is currently deployed. For example, it will be able to work on localhost, as well as on your public domain, without modifications.
Cheers!
relative pathes is resusable and you can run the web site on whatever location or url but absolute path make it related to one domain or location
Relative paths as explained by the rest has the benefit of porting website to different locations, and if you are version controlling my making different directories it can help at that and when the browsers looks within the server for relative paths its good optimzation technique because if a browsers encounters an absolute path it makes extra calls to the server to fetch it by looking up the location again and getting the file.
Relative paths tell the browser where a file is located relative to the document the browser is currently viewing. Since the paths are not based on the root directory, they are portable between different computers.
Sometimes we need to migrate our web applications/sites from one server/domain to another server/domain. A site with absolute paths/urls would need modifications to the paths/URLs accordingly while migrating. Relative path/url would not need to modifiy anything and the website/app would work perfectly in new environment.
If you build a site with relative paths, you probably understand that the content linked to in the relative path is stored on your domain or website.
However, absolute paths also work in this scenario, although it is cumbersome for the web programmer/developer.
Absolute paths should only be used when linking to content found on a different site.
Building a site with relative path is very useful as it will check the site before uploading and also it will display the page/site when we are at offline mode.
1. Good practice is not to embed complete paths including http:// etc that avoids extra web server calls which can be bad for server overhead.
2. You can change the base URL simply by changing it in the application configuration file which allows you to redeploy the application on the same or another server with a different name.
3. It allows you to change environments for production, staging, testing and development: for example: http://www.abc.com, dev.abc.com, staging.abc.com etc
Its make site easy to maintain , spcially in development envoirement if you made site with relative path you can move finish product without much changes to any location without any worry.
for security reasons .
relative paths will make it a little harder to understand your site directory structure and thats what we need when some unwanted person gets his hands on your site