-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
index.html
52 lines (45 loc) · 1.76 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<html>
<head>
<title>Mapbox GL JS Benchmarks</title>
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href='https://www.mapbox.com/base/latest/base.css' rel='stylesheet' />
<link rel='stylesheet' href='/dist/mapbox-gl.css'/>
<script href='https://unpkg.com/url-search-params@0.10.0/build/url-search-params.js'></script>
</head>
<body>
<div id="benchmarks"></div>
<script>
const params = new URLSearchParams(location.search.slice(1));
const localBenchScripts = ['/bench/benchmarks_generated.js', '/bench/benchmarks_view_generated.js'];
if (params.get('style_bench')) {
promisifyScripts(localBenchScripts);
} else {
Promise.resolve(params.has('compare') ?
params.getAll('compare').filter(Boolean) :
fetch('/package.json')
.then(response => response.json())
.then(pkg => [`v${pkg.version}`, 'master']))
.then(versions => {
const scripts = versions.map(v => `https://s3.amazonaws.com/mapbox-gl-js/${v}/benchmarks.js`)
.concat(localBenchScripts);
promisifyScripts(scripts);
})
.catch(err => console.error(err))
}
function promisifyScripts(scripts) {
return scripts.reduce((p, script) => p.then(() => loadScript(script)), Promise.resolve());
}
function loadScript(src) {
return new Promise(function (resolve, reject) {
const s = document.createElement('script');
s.src = src;
s.onload = resolve;
s.onerror = reject;
document.head.appendChild(s);
});
}
</script>
</body>
</html>