/
subject.js
35 lines (28 loc) · 963 Bytes
/
subject.js
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
window.loaded = [];
const head = document.querySelector('head');
const COUNT = 250;
window.__isLoaded = (run = 1) => {
return window.loaded.length === COUNT * 2 * run;
};
document.querySelector('[data-network]').addEventListener('click', () => {
const offset = window.loaded.length;
// Create many scripts
for (let i = offset; i < offset + COUNT; i++) {
const script = document.createElement('script');
script.src = `/virtual-assets/script-${i}.js`;
script.setAttribute('crossorigin', 'anonymous');
head.appendChild(script);
script.addEventListener('load', () => {
window.loaded.push(`script-${i}`);
});
}
});
document.querySelector('[data-fetch]').addEventListener('click', () => {
const offset = window.loaded.length;
// Make many fetch requests
for (let i = offset; i < offset + COUNT; i++) {
fetch(`/virtual-assets/fetch-${i}.json`).then(() => {
window.loaded.push(`fetch-${i}`);
});
}
});