mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Load css async
This commit is contained in:
parent
0d52793c27
commit
507121b886
26
gulp/html.js
26
gulp/html.js
@ -54,19 +54,19 @@ function gulptasksHTML($, gulp, buildFolder) {
|
|||||||
document.head.appendChild(css);
|
document.head.appendChild(css);
|
||||||
|
|
||||||
// Append async css
|
// Append async css
|
||||||
const asyncCss = document.createElement("link");
|
// const asyncCss = document.createElement("link");
|
||||||
asyncCss.rel = "stylesheet";
|
// asyncCss.rel = "stylesheet";
|
||||||
asyncCss.type = "text/css";
|
// asyncCss.type = "text/css";
|
||||||
asyncCss.media = "none";
|
// asyncCss.media = "none";
|
||||||
asyncCss.setAttribute("onload", "this.media='all'");
|
// asyncCss.setAttribute("onload", "this.media='all'");
|
||||||
asyncCss.href = cachebust("async-resources.css");
|
// asyncCss.href = cachebust("async-resources.css");
|
||||||
if (integrity) {
|
// if (integrity) {
|
||||||
asyncCss.setAttribute(
|
// asyncCss.setAttribute(
|
||||||
"integrity",
|
// "integrity",
|
||||||
computeIntegrityHash(path.join(buildFolder, "async-resources.css"))
|
// computeIntegrityHash(path.join(buildFolder, "async-resources.css"))
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
document.head.appendChild(asyncCss);
|
// document.head.appendChild(asyncCss);
|
||||||
|
|
||||||
if (app) {
|
if (app) {
|
||||||
// Append cordova link
|
// Append cordova link
|
||||||
|
@ -8,6 +8,7 @@ import { Signal } from "./signal";
|
|||||||
import { SOUNDS, MUSIC } from "../platform/sound";
|
import { SOUNDS, MUSIC } from "../platform/sound";
|
||||||
import { AtlasDefinition, atlasFiles } from "./atlas_definitions";
|
import { AtlasDefinition, atlasFiles } from "./atlas_definitions";
|
||||||
import { initBuildingCodesAfterResourcesLoaded } from "../game/meta_building_registry";
|
import { initBuildingCodesAfterResourcesLoaded } from "../game/meta_building_registry";
|
||||||
|
import { cachebust } from "./cachebust";
|
||||||
|
|
||||||
const logger = createLogger("background_loader");
|
const logger = createLogger("background_loader");
|
||||||
|
|
||||||
@ -110,6 +111,7 @@ export class BackgroundResourcesLoader {
|
|||||||
essentialBareGameSounds,
|
essentialBareGameSounds,
|
||||||
essentialBareGameAtlases
|
essentialBareGameAtlases
|
||||||
)
|
)
|
||||||
|
.then(() => this.internalPreloadCss("async-resources.scss"))
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
logger.warn("⏰ Failed to load essentials for bare game:", err);
|
logger.warn("⏰ Failed to load essentials for bare game:", err);
|
||||||
})
|
})
|
||||||
@ -136,6 +138,23 @@ export class BackgroundResourcesLoader {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internalPreloadCss(name) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
console.log("TODO");
|
||||||
|
|
||||||
|
const link = document.createElement("link");
|
||||||
|
|
||||||
|
link.onload = resolve;
|
||||||
|
link.onerror = reject;
|
||||||
|
|
||||||
|
link.setAttribute("rel", "stylesheet");
|
||||||
|
link.setAttribute("media", "all");
|
||||||
|
link.setAttribute("type", "text/css");
|
||||||
|
link.setAttribute("href", cachebust("async-resources.css"));
|
||||||
|
document.head.appendChild(link);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Array<string>} sprites
|
* @param {Array<string>} sprites
|
||||||
* @param {Array<string>} sounds
|
* @param {Array<string>} sounds
|
||||||
|
Loading…
Reference in New Issue
Block a user