JSFiddle - React, Tailwind, and code Playground
JavaScript CDN Speed Test
by Cople
JavaScript
var services = {
bootcdn: "http://cdn.bootcss.com/jquery/2.0.0/jquery.min.js",
upai: "http://upcdn.b0.upaiyun.com/libs/jquery/jquery-2.0.0.min.js",
staticfile: "http://cdn.staticfile.org/jquery/2.0.0/jquery.min.js",
360: "http://libs.useso.com/js/jquery/2.0.0/jquery.min.js",
baidu_code: "http://apps.bdimg.com/libs/jquery/2.0.0/jquery.min.js",
baidu_developer: "http://libs.baidu.com/jquery/2.0.0/jquery.min.js",
sae: "http://lib.sinaapp.com/js/jquery/2.0/jquery.min.js",
cdnjs: "http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js",
jsdelivr: "http://cdn.jsdelivr.net/jquery/2.0.0/jquery-2.0.0.min.js",
microsoft: "https://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.0.min.js",
google: "http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"
};
var logs = {};
function runTest(name, url, times) {
var startTime = Date.now();
return Promise.race([
fetch(url + "?_nocache=" + times + "__" + Date.now()),
new Promise(function(resolve, reject) {
setTimeout(() => reject(new Error('request timeout')), 5000)
})
])
.then(response => false)
.catch(error => error)
.then(function(error) {
if (!logs[name]) logs[name] = [];
var result = error ? Infinity : Date.now() - startTime;
console.log(name, result);
logs[name].push(result);
if (times > 1) {
return runTest(name, url, --times);
} else {
console.groupEnd();
};
});
};
var p = Promise.resolve("start");
Object.keys(services).forEach(function(name) {
var url = services[name];
p = p.then(function() {
console.group(name);
return runTest(name, url, 10);
});
});
p.then(function() {
var result = {};
Object.keys(logs).forEach(function(name, index, arr) {
var total = logs[name].reduce(function(prev, curr) {
return prev + curr;
});
result[name] = Math.round(total /...