编程语言
首页 > 编程语言> > Javascript不会在github页面网站上运行

Javascript不会在github页面网站上运行

作者:互联网

因此,javascript曾经在我的github页面网站上工作,但是在我删除存储库并试图通过一些更改重新上传项目后它不再起作用了.这是repo.这是site.

解决方法:

您通过HTTPS服务该站点,但尝试通过HTTP加载jQuery.这是不允许的.

<!-- wrong -->
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>

用https替换http,你应该好好去.如果您在浏览器中打开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.

标签:javascript,css,github,github-pages,html
来源: https://codeday.me/bug/20190712/1441451.html