【发布时间】:2017-01-08 19:13:56
【问题描述】:
我有一个异步加载我的 html 模板的函数:
loadTplAsync: function(path) {
return Q.Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open("GET", path, true);
xhr.onload = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
resolve(_.template(xhr.responseText));
} else {
reject(xhr.responseText);
}
}
};
xhr.onerror = error => reject(error);
xhr.send(null);
});
}
如何扩展此功能以缓存浏览器响应?
【问题讨论】:
-
您是否尝试过使用
ServiceWorker、Cache API?
标签: javascript ajax templates caching