现象:第一次加载JS文件,首次加载偶尔失败;
原因:require(['jquery', 'operamasks', 'zTree', 'jQueryCookie'],中前后引用同步加载;
解决方式:shim声明前置加载;
配置如下:
require.config({
baseUrl: 'js',
paths: {
jquery: 'lib/jquery/jquery.min',
operamasks: 'lib/operamasks/operamasks-ui.min',
zTree: 'lib/zTree/jquery.ztree.all-3.5.min',
jQueryCookie: 'lib/cookietool/jquery.cookie'
},
shim: {
'operamasks': ['jquery'],
'zTree': ['jquery']
}
});
require(['jquery', 'operamasks', 'zTree', 'jQueryCookie'], function ($, operamasks, zTree, cookie){ //前后引用同步加载
});
效果:
修改前:
修改后: