Using Absolute Versus Relative Paths for Images

后端 未结 3 1521
感情败类
感情败类 2021-01-05 12:59

A coworker just asked me if there were any reason why referring to images with a relative path would impede site speed.

While for cleanliness it\'s a good idea to h

3条回答
  •  孤街浪徒
    2021-01-05 13:40

    nah, there isn't any noticeable difference, and both have their uses. There is no DNS lookup client-side, it's the browser (or maybe the web server?) that changes the url to what it should be. Use them as what you need to, relative paths are more portable (no need to do anything to make them work in your development or live server), while absolute paths take you to specific location (regardless in what server you are).
    In my case, I use relative paths unless I want a specific address to be used. Also, when you're switching from non-secure to secure, you'd want to specify https so full path (or do an extra redirect somewhere else)

提交回复
热议问题