1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Vastly improve game loading time

This commit is contained in:
tobspr
2022-06-17 14:52:25 +02:00
parent 400cc5fe81
commit dfa392907d
18 changed files with 52 additions and 68 deletions

View File

@@ -76,15 +76,23 @@ function gulptasksHTML($, gulp, buildFolder) {
// Do not need to preload in app or standalone
if (!hasLocalFiles) {
// Preload essentials
const preloads = ["fonts/GameFont.woff2"];
const preloads = [
"res/fonts/GameFont.woff2",
"async-resources.css",
"res/sounds/music/theme-short.mp3",
];
preloads.forEach(src => {
const preloadLink = document.createElement("link");
preloadLink.rel = "preload";
preloadLink.href = cachebust("res/" + src);
preloadLink.href = cachebust(src);
if (src.endsWith(".woff2")) {
preloadLink.setAttribute("crossorigin", "anonymous");
preloadLink.setAttribute("as", "font");
} else if (src.endsWith(".css")) {
preloadLink.setAttribute("as", "style");
} else if (src.endsWith(".mp3")) {
preloadLink.setAttribute("as", "audio");
} else {
preloadLink.setAttribute("as", "image");
}