Javascript 不会 运行 在 github 个页面网站上
Javascript won't run on github pages site
所以 javascript 曾经在我的 github 页面站点上工作,但在我删除存储库并尝试重新上传项目并进行一些更改后它不再工作。这是 repo. Here is the site.
您正在通过 HTTPS 为站点提供服务,但试图通过 HTTP 加载 jQuery。这是不允许的。
<!-- wrong -->
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
将 http
替换为 https
就可以了。如果您在浏览器中打开 Javascript 控制台(通常在 F12 下),则很容易发现此错误。
<!-- correct -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
但是协议相关链接呢?
您也可以使用这种曾经流行的语法:
<!-- meh -->
<script src='//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
但此时它是货物崇拜。拼写 https://cdnjs.cloudflare.com/
更好。
原因如下:
- 您的 CDN 提供 HTTPS!那好极了。确保使用它。即使您的网站是通过纯 http (but why?) 交付的,您的用户至少仍然可以安全地获取资产。
- 如果您通过
file://
URI 在本地打开页面,该页面仍然有效,这有时在开发过程中很有用。
- The performance impact is negligible and you have no reason to worry about it.
Some advice from Paul Irish,Chrome背后的开发者之一:
If the asset you need is available on SSL, then always use the https://
asset.
It’s always safe to request HTTPS assets even if your site is on HTTP, however the reverse is not true.
当您使用 未指定 http protocols
可能是个好主意,不要将它们放在任何请求中...所以,而不是 http://
仅使用 //
.
console.log("$", window.jQuery)
<script src='//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
所以 javascript 曾经在我的 github 页面站点上工作,但在我删除存储库并尝试重新上传项目并进行一些更改后它不再工作。这是 repo. Here is the site.
您正在通过 HTTPS 为站点提供服务,但试图通过 HTTP 加载 jQuery。这是不允许的。
<!-- wrong -->
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
将 http
替换为 https
就可以了。如果您在浏览器中打开 Javascript 控制台(通常在 F12 下),则很容易发现此错误。
<!-- correct -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
但是协议相关链接呢?
您也可以使用这种曾经流行的语法:
<!-- meh -->
<script src='//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
但此时它是货物崇拜。拼写 https://cdnjs.cloudflare.com/
更好。
原因如下:
- 您的 CDN 提供 HTTPS!那好极了。确保使用它。即使您的网站是通过纯 http (but why?) 交付的,您的用户至少仍然可以安全地获取资产。
- 如果您通过
file://
URI 在本地打开页面,该页面仍然有效,这有时在开发过程中很有用。 - The performance impact is negligible and you have no reason to worry about it.
Some advice from Paul Irish,Chrome背后的开发者之一:
If the asset you need is available on SSL, then always use the
https://
asset.It’s always safe to request HTTPS assets even if your site is on HTTP, however the reverse is not true.
当您使用 未指定 http protocols
可能是个好主意,不要将它们放在任何请求中...所以,而不是 http://
仅使用 //
.
console.log("$", window.jQuery)
<script src='//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>