首页  >  文章  >  后端开发  >  引用requirejs,网速不好时,会提示require is not defined

引用requirejs,网速不好时,会提示require is not defined

WBOY
WBOY原创
2016-06-06 20:32:303782浏览

有的时候,可以输出'aaa'

但有的时候,会// Uncaught ReferenceError: require is not defined
图片描述
引用requirejs,网速不好时,会提示require is not defined

引用requirejs,网速不好时,会提示require is not defined


<code>require.config({
        baseUrl: '<?php echo $this->config->base_url(); ?>',
        paths: {
            jquery: 'assets/js/jquery.min',
            bootstrap: 'assets/js/bootstrap.min',
            fastclick: 'assets/js/fastclick',
            swal: 'assets/js/sweet-alert',
            bootstrapSelect: 'assets/js/bootstrap-select.min',
            ueditorConfig: 'assets/js/ueditor/ueditor.config',
            ueditor: 'assets/js/ueditor/ueditor.all.min',
            domReady: 'assets/js/domReady'
        },
        shim: {
            bootstrap: {
            deps: ['jquery'],
            exports: 'bootstrap'
            }
        },
        urlArgs: 'v=' + (new Date()).getTime()
    });


    require(['domReady'],function(domReady){
        domReady(function(){
            console.log('aaa');
        });
    });
    // Uncaught ReferenceError: require is not defined
</code>

回复内容:

有的时候,可以输出'aaa'

但有的时候,会// Uncaught ReferenceError: require is not defined
图片描述
引用requirejs,网速不好时,会提示require is not defined

引用requirejs,网速不好时,会提示require is not defined


<code>require.config({
        baseUrl: '<?php echo $this->config->base_url(); ?>',
        paths: {
            jquery: 'assets/js/jquery.min',
            bootstrap: 'assets/js/bootstrap.min',
            fastclick: 'assets/js/fastclick',
            swal: 'assets/js/sweet-alert',
            bootstrapSelect: 'assets/js/bootstrap-select.min',
            ueditorConfig: 'assets/js/ueditor/ueditor.config',
            ueditor: 'assets/js/ueditor/ueditor.all.min',
            domReady: 'assets/js/domReady'
        },
        shim: {
            bootstrap: {
            deps: ['jquery'],
            exports: 'bootstrap'
            }
        },
        urlArgs: 'v=' + (new Date()).getTime()
    });


    require(['domReady'],function(domReady){
        domReady(function(){
            console.log('aaa');
        });
    });
    // Uncaught ReferenceError: require is not defined
</code>

其实一般大家在生产环境里的时候是不会引用requirejs,上线的都是打包好的。

引入requirejs去掉asyn和defer属性

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn