首页 » HTML与CSS » 阅读文章
有条件使用Google API加载jQuery
Google API提供了jQuery的文件,可以帮助我们省一些流量,而且如果其他网站也是用了这个文件,那么就完全可以在浏览器缓存中,无需再次下载,节省了很多 时间,但是如果有些情况下加载失败了,网页也不能就这样不能用了啊,所以我们还需要检测一下,如果没有加载成功,就再加载自己服务器上的。
看看代码:
<!– Grab Google CDN jQuery. fall back to local if necessary –>
<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”></script>
<script>!window.jQuery && document.write(‘<script src=”js/jquery-1.4.2.min.js”><\/script>’)</script>
评论 共0条 (RSS 2.0) 发表评论