开发者

Is there a performance difference when writing an image src with a relative url versus using http://mysite.com/image.jpg?

I have a small script on artimap.com that I use to asychronously load images. Each images are the same transparent gif, but the rel attribute is the real adress of the image. The javaScript reads the rel attribute and load that image. I plan to put "http://artimap.com/" before all the images开发者_StackOverflow that I load instead of using relative src because that will be easier to manage the files on that multilingual website. Is there a difference in speed, or server load with using relative src versus absolute src when loading multiples images in a web page ?


Is there a difference in speed, or server load with usin relative src versus absolute src when loading multiples images in a web page ?

No, or just a very very minuscule one. Relative URLs are resolved by the client (=browser) relative to the current location (= the loaded page). When the request is made to the server, it is always with the full URL.

The time needed by the browser to determine the current location, and to calculate the relative URL is absolutely negligeable.

You should be safe using relative URLs performance wise, because even if that micro-performance mattered, JavaScript is bound to be slower in calculating the full URL than the browser.


If here is a real performance difference between relative URLs and absolute ones I would consider it to be a bug in he browser...

But I am certain there is a big difference in testability : if your pages reference abolute URL how can you set up a test site of a version you are developping ?

You will end up testing the production site rather than the test one... except if you change all URLs in your test site and don't forget to put them back for production.

Relative URL where not invented to save some typing but because they make your life easier ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜