速记 http://as//用于脚本和链接标签?有人看过/使用过吗? [英] shorthand http:// as // for script and link tags? anyone see / use this before?

查看:18
本文介绍了速记 http://as//用于脚本和链接标签?有人看过/使用过吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题如下:

如果您使用 addthis(共享按钮)查看任何站点...

一旦您将鼠标悬停在 addthis 按钮上,并且加载了所有必需的资产后,请使用 firebug 或 chrome 检查器查看文档正文(不是源文件,屏幕上的实际文档...对象检查器).您会注意到 addthis 自动加载的附加资产如下所示:

<script type="text/javascript" src="//s7.addthis.com/static/r07/menu78.js"></script><link rel="stylesheet" type="text/css" href="//s7.addthis.com/static/r07/widget61.css" media="all">

上面标签中 http://的缩写是什么?

有人用过这个吗?它有官方"名称吗?这种简写http协议的方法跨浏览器的兼容性如何?

是的,我知道这会破坏爬虫/搜索引擎优化,但我正在考虑在机器人无法访问(主要是 js 处理的东西)的情况下开始使用它.

好主意还是坏主意?

解决方案

// 开头的 URL 表示使用不同的服务器但保持相同的方案"

因此,如果您从 https://example.com/ 加载 //example.net/script,它将获得 https://example.net/script,而如果你从 http://example.com/ 加载它,它会得到 http://example.net/script.>

另一方面,如果您从 file://c:/Users/You/Documents/test.html 加载它,那么它可能不会解析为任何有用的东西.如果使用此语法,请确保使用本地 Web 服务器进行开发(并访问 http://localhost/).

这是 URI 的标准部分,得到很好的支持,通常称为方案相对 URI"

the question is as follows:

if you take a look at any site using addthis (the share button)...

once you float over the addthis button, and all of the required assets load take a look at the body of the document using firebug or chrome inspector (not the source, the actual document that is sitting on your screen... the object inspector). you will notice that the additional assets loaded automatically by addthis look something like this:

<script type="text/javascript" src="//s7.addthis.com/static/r07/menu78.js"></script>
<link rel="stylesheet" type="text/css" href="//s7.addthis.com/static/r07/widget61.css" media="all">

what is this short handing of http:// in the above tags?

has anyone used this before? does it have an 'official' name? how cross browser compatible is this method of short handing the http protocal?

yes, i understand this will break things as far as crawlers / seo go, but i am thinking about starting to use this in situations that are inaccessible (mainly, js handled stuff) to bots.

good or bad idea?

解决方案

Starting a URL with // means "Use a different server but keep the same scheme"

So if you load //example.net/script from https://example.com/ it will get https://example.net/script, while if you load it from http://example.com/ it will get http://example.net/script.

If, on the other hand, you load it from file://c:/Users/You/Documents/test.html then it will probably not resolve to anything useful. Make sure you do development with a local web server (and access http://localhost/) if you use this syntax.

This is a standard part of URIs, it well supported, and is usually known as "scheme relative URIs"

这篇关于速记 http://as//用于脚本和链接标签?有人看过/使用过吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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