//在src =“”属性上使用而不是http://

时间:2012-09-12 16:21:00

标签: javascript jquery html

  

可能重复:
  shorthand as // for script and link tags? anyone see / use this before?

我想我明白发生了什么,但谷歌搜索时没有找到任何确定的内容。在这样的代码中:

// talking about the src attribute
<script type="text/javascript" src="//use.typekit.net/%kitid%.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>

我习惯了http://在那里。当我在http服务器上调用此页面时,它会对资源进行常规HTTP请求,因此我假设这是http://的快捷方式。我猜这与不知道您所在的页面是否要使用https://或http://有关?是否有任何关于这种做法的文章或任何信息?

1 个答案:

答案 0 :(得分:8)

使用//,请求将模仿父母页面中的协议。

看看这个:http://paulirish.com/2010/the-protocol-relative-url/