Advantages and disadvantages of relative paths and absolute paths

Source: Internet
Author: User
 

In the previous article, I talked about  the meaning and writing methods of absolute and relative paths , so some friends asked when to use absolute paths. When to use a relative path.


    They have their own advantages and disadvantages.


    When in fact there is no absolute answer using absolute and relative paths , different paths are used depending on the situation.


    In my own custom, for example, the page is used as a relative address, because it does not have to be on its own machine virtual out of the network environment can also preview the page normally.


    But before I go online, I'll follow a few steps:


    1. Upload the picture file to the server first;


    2. Then change the picture address in the CSS file to the absolute path and upload it to the server;


    3. Then the Web page in the CSS address, picture address, and so on to the absolute address, uploaded to the server up.


    Of course, it is not a must to do so, it is a personal habit. If it is for others to do things, do not need to upload their own, as long as the relative path of packaging to send to each other.


    Why did you do that? Take a look at the pros and cons of the absolute path and relative path below
.


    With respect to the pros and cons of absolute paths and relative paths, Google employee Johnmu a more comprehensive summary of Google Groups (in English)
. He explained the absolute path and the relative strength of the strengths and weaknesses of the relatively complete, I combined their own experience, a summary.


Advantages of absolute paths 

1. If someone copied your site content, the link will also point to your site, some people are more lazy plagiarism, will not change the content. In fact, is not limited to plagiarism, if someone will save your web page to the local computer, the links, pictures, CSS, and JS will still be connected to your site.


2. If the page location changes, the link in the inside or point to the correct URL. 

Disadvantages of absolute paths: 

1. As I mentioned above, the absolute path cannot be used when this mechanism is done because the link should point to the real domain name rather than the tester. 

2. Content pages must be fixed, if all content pages use absolute path, then to modify a file, the path on other pages can not be changed, but also point to the original address. 

advantages and disadvantages of relative paths 

The relative path has the advantages and disadvantages and the absolute path is almost the opposite. 

Advantages: 

1. Easy to move content, you can move the entire directory. 

2. The test method is more flexible, which is what I call the test of the machine is more convenient. 

Disadvantages: 

1. When the content page changed position, the link is easy to fail. 

2. Easy to be collected by the People's Congress area plagiarism. 

Other: 

Some people say that using absolute path can be beneficial to search engine crawl, in fact, the relative path does not affect search crawl. 

The path should be as reduced as possible, preferably no more than 4 layers of links, which is conducive to search engine crawling.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.