我随机得到了jquery错误 [英] I got jquery errors randomly

查看:52
本文介绍了我随机得到了jquery错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用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


未捕获的ReferenceError:未定义jQuery(匿名函数)@jquery.easing.1.3。 js:37

jquery.anyslider.js:4

未捕获的ReferenceError:jQuery未定义(匿名函数)@ jquery.anyslider.js:4
custom.js :3

未捕获的ReferenceError:$未定义(匿名函数)@ custom.js:3
flytocart.js:1

未捕获的ReferenceError:$未定义

Uncaught ReferenceError: jQuery is not defined(anonymous function) @ jquery.easing.1.3.js:37
jquery.anyslider.js:4
Uncaught ReferenceError: jQuery is not defined(anonymous function) @ jquery.anyslider.js:4 custom.js:3
Uncaught ReferenceError: $ is not defined(anonymous function) @ custom.js:3 flytocart.js:1
Uncaught ReferenceError: $ is not defined

如果我在页面刷新,错误就会消失,一切正常。如果我再次刷新有错误。我随机收到错误。

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错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆