links without http: like //code.jquery.com/etc [closed]

一曲冷凌霜 提交于 2019-12-06 03:29:23

问题


Lately I've noticed that some sites (such as jsFiddle) and some widgets such pinterest feed widget, and many others.

They started to use links in the format

  • //code.jquery.com/jquery-1.9.1.js
  • //assets.pinterest.com/js/pinit.js

    1. what does the // means ?
    2. is it the same as http ?
    3. if // is the same as http why using it instead of http ?
    4. if both are different, can I use it to link my website ?

as addition: I'm not sure, but I think I've seem some use //name:sub.domaine.com, am I wrong ? if those exist, what do they mean ?

Edit:

as explained in an answer bellow, I can use the // notation to make my links shorter, but when I use it for my website: Chrome changes the link to: file:/// which is not what I expected


回答1:


This is a protocol-relative URL. If the page which includes it uses HTTP, then it's HTTP. If the page which includes it uses HTTPS, then it uses HTTPS.

This is convenient so that you can ensure that you don't fetch insecure resources in a secure page (this causes the "mixed content" warning you might have seen), without bothering with the overhead of SSL/TLS in a page which is delivered unencrypted anyhow.

It's similar to how URLs beginning with a single / are resolved relative to the current protocol and hostname, and URLs with no leading / or scheme are resolved relative to the current page's directory.




回答2:


To keep it simple: most web browsers now do not require the full [http://www] anymore. So yes, to be cool and to keep the URL's short, you can skip the full [http://www.] and just use //



来源:https://stackoverflow.com/questions/15692601/links-without-http-like-code-jquery-com-etc

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