What is the best way to link to domain root?

你说的曾经没有我的故事 提交于 2019-12-23 06:48:40

问题


I'm setting up links and not sure which is the best way to link to the domain root should I do

<a href="/">home</a> or <a href="http://example.com">home</a> ?

is there a cooler way that I'm unaware of?


回答1:


Unless you have a specific reason you want to always use HTTP, use <a href="/">text</a>. You'll run into problems with SSL otherwise.

There is a cooler way to do it if you're loading scripts, and that is to load cross domain scripts in a protocol-neutral way, as such:

<script src="//example-cdn.com/scripts/jquery-latest-min.js"></script>

That way you avoid the HTTP mixed content warnings in IE.




回答2:


the simpler / variant is portable across domains, might be considered as an advantage.




回答3:


depends on the programming language you are using.. and the web-framework.. in plain html / would be your choice (portability)



来源:https://stackoverflow.com/questions/5553796/what-is-the-best-way-to-link-to-domain-root

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!