Github js、css加载慢或者失败

JavaScript017

Github js、css加载慢或者失败,第1张

将一下内容复制进去

# GitHub Start

192.30.253.112 github.com

192.30.253.119 gist.github.com

151.101.100.133 assets-cdn.github.com

151.101.100.133 raw.githubusercontent.com

151.101.100.133 gist.githubusercontent.com

151.101.100.133 cloud.githubusercontent.com

151.101.100.133 camo.githubusercontent.com

151.101.100.133 avatars0.githubusercontent.com

151.101.100.133 avatars1.githubusercontent.com

151.101.100.133 avatars2.githubusercontent.com

151.101.100.133 avatars3.githubusercontent.com

151.101.100.133 avatars4.githubusercontent.com

151.101.100.133 avatars5.githubusercontent.com

151.101.100.133 avatars6.githubusercontent.com

151.101.100.133 avatars7.githubusercontent.com

151.101.100.133 avatars8.githubusercontent.com

# GitHub End

cmd内输入命令ipconfig /flushdns刷新dns缓存,ipconfig /displaydns查看dns缓存

打开github

原因1:如果你是想直接使用git网上的文件的话,你需要找到git cdn上的该js文件链接地址,放到script的src标签里即可。

原因2:如果是想动态加载js,那可能的原因是js还未加载完全就执行导致出错。

若是原因2,可使用以下代码:

var ele = document.createElement('script'),

_head = document.getElementsByTagName('head')[0]

ele.type='text/javascript'

ele.src = "forGaofei这个文件的路径地址"

_head.appendChild(ele)

if (ele.readyState){ //IE

ele.onreadystatechange = function(){

if (ele.readyState == "loaded" || ele.readyState == "complete"){

ele.onreadystatechange = null

doSomething()

}

}

} else { //Firefox, Safari, Chrome, Opera

ele.onload = function(){

doSomething()

}

}

function doSomething(){

//需要此文件才能做的事情写在这里调用

}