html src和href属性的相对路径或url [英] Relative path or url for html src and href attributes

查看:634
本文介绍了html src和href属性的相对路径或url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用框架可以轻松地为我的html src和href属性列出完整的网址,我觉得通过列出一个完整的网址而不是相对路径,我会更全面。但是这更快吗?我是否需要额外的DNS查找?当内容在同一台服务器上时,最佳做法是什么?

Using a framework makes it easy to list full url's for my html src and href attributes, and I feel I'm being more thorough by listing a full url instead of a relative path. But is this faster? Am I incurring an extra DNS lookup? What is the best practice when the content is on the same server?

< img src ='http://site.com/images /img1.png'/>

vs

<img src='/images/img1.png' />

Codeigniter的图片助手img()的工作方式如此用户指南

Codeigniter's image helper img() works like this from the users' guide:

echo img('images/picture.jpg');
// gives <img src="http://site.com/images/picture.jpg" />

并且Codeigniter的锚定助手anchor()的工作方式如此用户指南

and Codeigniter's anchor helper anchor() works like this from the users guide:

echo anchor('news/local/123','My News');
// gives <a href="http://example.com/index.php/news/local/123" >My News</a>


推荐答案

如果你有相对或绝对URL。您的浏览器最终会将服务器URI预先挂起到前端。此外,您的网络堆栈首次执行查找,并缓存IP。除非出现错误,否则每页只能有一次查找。 YMMV当然,但应该是这一切如何工作。

As far as DNS goes, it really doesn't matter if you have relative or absolute URL. Your browser ends up pre-pending the server URI onto the front anyway. Also, your network stack does the lookup for the first time, and caches the IP. Unless something goes wrong, there should only be the one lookup per page. YMMV of course, but that should be how this all works.

这篇关于html src和href属性的相对路径或url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆