mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-22 15:56:17 -04:00
Parallelize asset loading
This commit is contained in:
parent
9847feeb52
commit
d8f9532039
1 changed files with 30 additions and 22 deletions
|
@ -56,13 +56,16 @@ class PairDrop {
|
|||
await this.backgroundCanvas.fadeIn();
|
||||
|
||||
// Load deferred assets
|
||||
console.log("Load deferred assets...");
|
||||
await this.loadDeferredAssets();
|
||||
console.log("Loading of deferred assets completed.");
|
||||
|
||||
console.log("Hydrate UI...");
|
||||
await this.hydrate();
|
||||
console.log("UI hydrated.");
|
||||
|
||||
// Evaluate url params as soon as ws is connected
|
||||
console.log("Evaluate URL params when websocket connection is established.");
|
||||
Events.on('ws-connected', _ => this.evaluateUrlParams(), {once: true});
|
||||
}
|
||||
|
||||
|
@ -102,14 +105,11 @@ class PairDrop {
|
|||
}
|
||||
}
|
||||
|
||||
async loadDeferredAssets() {
|
||||
console.log("Load deferred assets");
|
||||
for (const url of this.deferredStyles) {
|
||||
await this.loadAndApplyStylesheet(url);
|
||||
}
|
||||
for (const url of this.deferredScripts) {
|
||||
await this.loadAndApplyScript(url);
|
||||
}
|
||||
loadDeferredAssets() {
|
||||
const stylePromises = this.deferredStyles.map(url => this.loadAndApplyStylesheet(url));
|
||||
const scriptPromises = this.deferredScripts.map(url => this.loadAndApplyScript(url));
|
||||
|
||||
return Promise.all([...stylePromises, ...scriptPromises]);
|
||||
}
|
||||
|
||||
loadStyleSheet(url) {
|
||||
|
@ -125,13 +125,16 @@ class PairDrop {
|
|||
});
|
||||
}
|
||||
|
||||
async loadAndApplyStylesheet(url) {
|
||||
try {
|
||||
await this.loadStyleSheet(url);
|
||||
console.log(`Stylesheet loaded successfully: ${url}`);
|
||||
} catch (error) {
|
||||
console.error('Error loading stylesheet:', error);
|
||||
}
|
||||
loadAndApplyStylesheet(url) {
|
||||
return new Promise( async (resolve) => {
|
||||
try {
|
||||
await this.loadStyleSheet(url);
|
||||
console.log(`Stylesheet loaded successfully: ${url}`);
|
||||
resolve();
|
||||
} catch (error) {
|
||||
console.error('Error loading stylesheet:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
loadScript(url) {
|
||||
|
@ -145,13 +148,16 @@ class PairDrop {
|
|||
});
|
||||
}
|
||||
|
||||
async loadAndApplyScript(url) {
|
||||
try {
|
||||
await this.loadScript(url);
|
||||
console.log(`Script loaded successfully: ${url}`);
|
||||
} catch (error) {
|
||||
console.error('Error loading script:', error);
|
||||
}
|
||||
loadAndApplyScript(url) {
|
||||
return new Promise( async (resolve) => {
|
||||
try {
|
||||
await this.loadScript(url);
|
||||
console.log(`Script loaded successfully: ${url}`);
|
||||
resolve();
|
||||
} catch (error) {
|
||||
console.error('Error loading script:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async hydrate() {
|
||||
|
@ -223,6 +229,8 @@ class PairDrop {
|
|||
// remove url params from url
|
||||
const urlWithoutParams = getUrlWithoutArguments();
|
||||
window.history.replaceState({}, "Rewrite URL", urlWithoutParams);
|
||||
|
||||
console.log("URL params evaluated.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue