XMLHttpRequest
CDNSpeed项目 记录接口响应时间和文件大小。
request: function (method, url, headers) { var startTime = new Date().getTime(); return $q(function (resolve, reject) { var xhr = new XMLHttpRequest(); xhr.open(method, url, true); if (typeof headers === 'object') { for (var key in headers) { xhr.setRequestHeader(key, headers[key]); } } xhr.onreadystatechange = function (e) { if (xhr.readyState == 4) { if (xhr.status == 200) { resolve({ size: xhr.response.length, time: new Date().getTime() - startTime }); } else { reject(); } } }; xhr.send(); }); },
|