Javascript 使用Yepnope加载全局脚本和条件脚本的最佳方法
我有大约8个js文件需要在我的站点的每个页面上加载,另外还有一些需要有条件加载的文件。我已经把事情做好了,我只是想确保我做的尽可能优雅(我怀疑我不是这样) 以下是我当前使用的代码:Javascript 使用Yepnope加载全局脚本和条件脚本的最佳方法,javascript,asynchronous,yepnope,Javascript,Asynchronous,Yepnope,我有大约8个js文件需要在我的站点的每个页面上加载,另外还有一些需要有条件加载的文件。我已经把事情做好了,我只是想确保我做的尽可能优雅(我怀疑我不是这样) 以下是我当前使用的代码: yepnope({ load: { 'jquery': '/include/js/libraries/jquery-1.8rc1.js', 'ui': '/include/js/jquery-ui-1.8.16.custom.min.js',
yepnope({
load: {
'jquery': '/include/js/libraries/jquery-1.8rc1.js',
'ui': '/include/js/jquery-ui-1.8.16.custom.min.js',
'global': '/include/js/global.js',
'dbObject': '/include/js/dbObject.js',
'dbQuery': '/include/js/dbQuery.js',
'common': '/include/js/common.js',
'credit': '/include/js/credit.js',
'messages': '/include/js/messages.js',
'poller': '/include/js/poller.js',
'ajax_global': '/include/js/ajax_global.js'
},
complete: function (url, res, key) {
yepnope({
test: $('body').hasClass('project'),
yep: {
'project': '/include/js/project.js'
},
callback: function(url, res, key) {
}
});
}
});
必须为站点上的每个页面加载初始load
对象中的所有内容。然后在complete
函数中,我正在测试body标记是否具有project
类,如果是这样,我将加载此页面所依赖的其他脚本
两个问题:
非常感谢您的帮助。这方面有什么进展吗?我正在考虑使用yepnope,这对我来说也是一个问题