问题描述
我用jQuery和Javascript创建了网站。我注意到有时JS文件加载不好。
我在控制台中遇到这些错误
I made website with jQuery and Javascript. I noticed that sometimes the JS file are not loading well.I got these errors in console
如果我在页面刷新,错误就会消失,一切正常。如果我再次刷新有错误。我随机收到错误。
If I refresh on page the errors are gone, and everything works properly. If I refresh again got errors. I got errors randomly.
我的JS文件全部在头部
My JS files all in the head section
<script async src="js/jquery-1.11.3.min.js"></script>
<script async src="js/jquery-ui.min.js"></script>
<script async src="js/jquery.easing.1.3.js"></script>
<script async src="js/jquery.anyslider.js"></script>
<script>
WebFontConfig = {
google: { families: ['Open+Sans:400italic,600italic,700italic,800italic,700,600,800,400:latin,latin-ext', 'Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic:latin,latin-ext', 'Roboto+Condensed:300italic,400italic,700italic,400,300,700:latin,latin-ext'] }
};
var cb = function () {
var wf = document.createElement('script');
wf.src = '//ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
};
var raf = requestAnimationFrame || mozRequestAnimationFrame || webkitRequestAnimationFrame || msRequestAnimationFrame;
if (raf) {
raf(cb);
} else {
window.addEventListener('load', cb);
}
</script>
<script async src="js/custom.js"></script>
<script async src="js/flytocart.js"></script>
<script src='https://www.google.com/recaptcha/api.js'></script>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
原因可能是什么?我该如何解决?
What could be the reasons? How can I fix it?
感谢所有帮助
推荐答案
正如您已将 async
添加到脚本标记中。是的,它不会阻止您的页面呈现,但不保证按照您在页面中添加的相同顺序下载这些脚本。
As you have added async
to you script tags. Yes it will not block rendering of your page but it is not guaranteed to download those script in the same order in which you have added in page.
因此请在删除后尝试来自脚本标签的code> async 。
So try after removing async
from script tags.
这篇关于我随机得到了jquery错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!