我使用pjax独立和pace.js来显示页面加载进度。一切都很顺利。
不过,我有一个脚本,我在点击一个相当大的按钮(houndify-web-sdk.min.js 700 of )之后动态加载,并希望显示这个加载的进度。
该脚本目前正在按如下方式添加:
var newScript = document.createElement("script");
newScript.setAttribute("src", "/js/large-script.min.js");
document.body.appendChild(newScript);是否有可能获得跟踪这一负荷的速度?
我也尝试了下面的Pace.track函数,没有任何结果。
Pace.track(function() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://large.min.js", true);
xhr.responseType = "text";
xhr.onload = function() {
if (this.status === 200) {
console.log("loaded");
// not sure how I would then put the response into a script src file
}
};
xhr.send();
});任何帮助/建议都将不胜感激!
发布于 2016-04-30 11:41:42
如果其他人在这方面有问题-使用jQuery.getScript()很好。要启用缓存,最好如下所示:
$.ajax({
url: url,
dataType: "script",
success: success,
cache: true
});https://stackoverflow.com/questions/36923204
复制相似问题