来自https://github.com/ccoenraets/backbone-jax-cellar/blob/master/WebContent/js/utils.js:
tpl = {
// Hash of preloaded templates for the app
templates: {},
// Recursively pre-load all the templates for the app.
// This implementation should be changed in a production environment. All the template files should be
// concatenated in a single file.
loadTemplates: function(names, callback) {
var that = this;
var loadTemplate = function(index) {
var name = names[index];
console.log('Loading template: ' + name);
$.get('tpl/' + name + '.html', function(data) {
that.templates[name] = data;
index++;
if (index < names.length) {
loadTemplate(index);
} else {
callback();
}
});
}
loadTemplate(0);
},
// Get template by name from hash of preloaded templates
get: function(name) {
return this.templates[name];
}
};
我应该做类似的事情吗
$.get('tpl/all-tpls.html', function(data) { }
获取所有的 html 模板?这不是不必要地获取一堆 html 吗?我们的应用程序是用 Java 构建的,我们正在使用https://github.com/samaxes/minify-maven-plugin来缩小和合并我们的 js 和 css 文件。任何方向将不胜感激。