1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-14 10:41:52 +00:00

Remove cache busting

Cache busting is not required in standalone context.
This commit is contained in:
Danyil Hryhoriev 2024-04-20 13:00:02 +03:00 committed by Даниїл Григор'єв
parent e10edca73e
commit f2596ef845
12 changed files with 29 additions and 91 deletions

View File

@ -32,11 +32,3 @@ export function getVersion() {
// Use the version number specified in package.json // Use the version number specified in package.json
return JSON.parse(fs.readFileSync("../package.json", "utf-8")).version; return JSON.parse(fs.readFileSync("../package.json", "utf-8")).version;
} }
/**
* @param {string} url
* @param {string} commitHash
*/
export function cachebust(url, commitHash) {
return "/v/" + commitHash + "/" + url;
}

View File

@ -1,5 +1,5 @@
import path from "path/posix"; import path from "path/posix";
import { getRevision, cachebust } from "./buildutils.js"; import { getRevision } from "./buildutils.js";
import gulpPostcss from "gulp-postcss"; import gulpPostcss from "gulp-postcss";
import postcssAssets from "postcss-assets"; import postcssAssets from "postcss-assets";
@ -16,21 +16,15 @@ import gulpRename from "gulp-rename";
export default function gulptasksCSS(gulp, buildFolder, browserSync) { export default function gulptasksCSS(gulp, buildFolder, browserSync) {
// The assets plugin copies the files // The assets plugin copies the files
const commitHash = getRevision(); const commitHash = getRevision();
const postcssAssetsPlugin = enableCachebust => const postcssAssetsPlugin = postcssAssets({
postcssAssets({
loadPaths: [path.join(buildFolder, "res", "ui")], loadPaths: [path.join(buildFolder, "res", "ui")],
basePath: buildFolder, basePath: buildFolder,
baseUrl: ".", baseUrl: ".",
cachebuster: enableCachebust
? (filePath, urlPathname) => ({
pathname: cachebust(urlPathname, commitHash),
})
: "",
}); });
// Postcss configuration // Postcss configuration
const postcssPlugins = (prod, { cachebust = false }) => { const postcssPlugins = prod => {
const plugins = [postcssAssetsPlugin(cachebust)]; const plugins = [postcssAssetsPlugin];
if (prod) { if (prod) {
plugins.unshift( plugins.unshift(
postcssPresetEnv({ postcssPresetEnv({
@ -69,7 +63,7 @@ export default function gulptasksCSS(gulp, buildFolder, browserSync) {
.pipe(gulpSassLint.failOnError()); .pipe(gulpSassLint.failOnError());
}); });
function resourcesTask({ cachebust, isProd }) { function resourcesTask({ isProd }) {
return gulp return gulp
.src("../src/css/main.scss") .src("../src/css/main.scss")
.pipe(gulpPlumber()) .pipe(gulpPlumber())
@ -82,27 +76,22 @@ export default function gulptasksCSS(gulp, buildFolder, browserSync) {
]) ])
) )
.pipe(gulpRename("async-resources.css")) .pipe(gulpRename("async-resources.css"))
.pipe(gulpPostcss(postcssPlugins(isProd, { cachebust }))) .pipe(gulpPostcss(postcssPlugins(isProd)))
.pipe(gulp.dest(buildFolder)) .pipe(gulp.dest(buildFolder))
.pipe(browserSync.stream()); .pipe(browserSync.stream());
} }
// Builds the css resources // Builds the css resources
gulp.task("css.resources.dev", () => { gulp.task("css.resources.dev", () => {
return resourcesTask({ cachebust: false, isProd: false }); return resourcesTask({ isProd: false });
}); });
// Builds the css resources in prod (=minified) // Builds the css resources in prod (=minified)
gulp.task("css.resources.prod", () => { gulp.task("css.resources.prod", () => {
return resourcesTask({ cachebust: true, isProd: true }); return resourcesTask({ isProd: true });
}); });
// Builds the css resources in prod (=minified), without cachebusting function mainTask({ isProd }) {
gulp.task("css.resources.prod-standalone", () => {
return resourcesTask({ cachebust: false, isProd: true });
});
function mainTask({ cachebust, isProd }) {
return gulp return gulp
.src("../src/css/main.scss") .src("../src/css/main.scss")
.pipe(gulpPlumber()) .pipe(gulpPlumber())
@ -115,30 +104,21 @@ export default function gulptasksCSS(gulp, buildFolder, browserSync) {
}), }),
]) ])
) )
.pipe(gulpPostcss(postcssPlugins(isProd, { cachebust }))) .pipe(gulpPostcss(postcssPlugins(isProd)))
.pipe(gulp.dest(buildFolder)) .pipe(gulp.dest(buildFolder))
.pipe(browserSync.stream()); .pipe(browserSync.stream());
} }
// Builds the css main // Builds the css main
gulp.task("css.main.dev", () => { gulp.task("css.main.dev", () => {
return mainTask({ cachebust: false, isProd: false }); return mainTask({ isProd: false });
}); });
// Builds the css main in prod (=minified) // Builds the css main in prod (=minified)
gulp.task("css.main.prod", () => { gulp.task("css.main.prod", () => {
return mainTask({ cachebust: true, isProd: true }); return mainTask({ isProd: true });
});
// Builds the css main in prod (=minified), without cachebusting
gulp.task("css.main.prod-standalone", () => {
return mainTask({ cachebust: false, isProd: true });
}); });
gulp.task("css.dev", gulp.parallel("css.main.dev", "css.resources.dev")); gulp.task("css.dev", gulp.parallel("css.main.dev", "css.resources.dev"));
gulp.task("css.prod", gulp.parallel("css.main.prod", "css.resources.prod")); gulp.task("css.prod", gulp.parallel("css.main.prod", "css.resources.prod"));
gulp.task(
"css.prod-standalone",
gulp.parallel("css.main.prod-standalone", "css.resources.prod-standalone")
);
} }

View File

@ -251,10 +251,7 @@ for (const variant in BUILD_VARIANTS) {
gulp.task(buildName + ".resourcesAndCode", gulp.parallel("step.baseResources", buildName + ".code")); gulp.task(buildName + ".resourcesAndCode", gulp.parallel("step.baseResources", buildName + ".code"));
gulp.task( gulp.task(buildName + ".all", gulp.series(buildName + ".resourcesAndCode", "css.prod", "html.prod"));
buildName + ".all",
gulp.series(buildName + ".resourcesAndCode", "css.prod-standalone", "html.prod")
);
gulp.task(buildName, gulp.series("utils.cleanup", buildName + ".all", "step.postbuild")); gulp.task(buildName, gulp.series("utils.cleanup", buildName + ".all", "step.postbuild"));

View File

@ -6,7 +6,6 @@ import { initSpriteCache } from "../game/meta_building_registry";
import { MUSIC, SOUNDS } from "../platform/sound"; import { MUSIC, SOUNDS } from "../platform/sound";
import { T } from "../translations"; import { T } from "../translations";
import { AtlasDefinition, atlasFiles } from "./atlas_definitions"; import { AtlasDefinition, atlasFiles } from "./atlas_definitions";
import { cachebust } from "./cachebust";
import { Loader } from "./loader"; import { Loader } from "./loader";
import { createLogger } from "./logging"; import { createLogger } from "./logging";
import { Signal } from "./signal"; import { Signal } from "./signal";
@ -200,8 +199,7 @@ export class BackgroundResourcesLoader {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
let notifiedNotComputable = false; let notifiedNotComputable = false;
const fullUrl = cachebust(src); xhr.open("GET", src, true);
xhr.open("GET", fullUrl, true);
xhr.responseType = "arraybuffer"; xhr.responseType = "arraybuffer";
xhr.onprogress = function (ev) { xhr.onprogress = function (ev) {
if (ev.lengthComputable) { if (ev.lengthComputable) {
@ -225,7 +223,7 @@ export class BackgroundResourcesLoader {
xhr.onloadend = function () { xhr.onloadend = function () {
if (!xhr.status.toString().match(/^2/)) { if (!xhr.status.toString().match(/^2/)) {
reject(fullUrl + ": " + xhr.status + " " + xhr.statusText); reject(src + ": " + xhr.status + " " + xhr.statusText);
} else { } else {
if (!notifiedNotComputable) { if (!notifiedNotComputable) {
progressHandler(1); progressHandler(1);

View File

@ -1,10 +0,0 @@
/**
* Generates a cachebuster string. This only modifies the path in the browser version
* @param {string} path
*/
export function cachebust(path) {
if (G_IS_BROWSER && !G_IS_STANDALONE && !G_IS_DEV) {
return "/v/" + G_BUILD_COMMIT_HASH + "/" + path;
}
return path;
}

View File

@ -1,6 +1,5 @@
import { makeOffscreenBuffer } from "./buffer_utils"; import { makeOffscreenBuffer } from "./buffer_utils";
import { AtlasSprite, BaseSprite, RegularSprite, SpriteAtlasLink } from "./sprites"; import { AtlasSprite, BaseSprite, RegularSprite, SpriteAtlasLink } from "./sprites";
import { cachebust } from "./cachebust";
import { createLogger } from "./logging"; import { createLogger } from "./logging";
/** /**

View File

@ -4,7 +4,6 @@ import { GameRoot } from "../../root";
import { MinerComponent } from "../../components/miner"; import { MinerComponent } from "../../components/miner";
import { DynamicDomAttach } from "../dynamic_dom_attach"; import { DynamicDomAttach } from "../dynamic_dom_attach";
import { TrackedState } from "../../../core/tracked_state"; import { TrackedState } from "../../../core/tracked_state";
import { cachebust } from "../../../core/cachebust";
import { T } from "../../../translations"; import { T } from "../../../translations";
import { enumItemProcessorTypes, ItemProcessorComponent } from "../../components/item_processor"; import { enumItemProcessorTypes, ItemProcessorComponent } from "../../components/item_processor";
import { ShapeItem } from "../../items/shape_item"; import { ShapeItem } from "../../items/shape_item";
@ -190,7 +189,7 @@ export class HUDInteractiveTutorial extends BaseHUDPart {
document.documentElement.setAttribute("data-tutorial-step", hintId); document.documentElement.setAttribute("data-tutorial-step", hintId);
this.elementGif.style.backgroundImage = this.elementGif.style.backgroundImage =
"url('" + cachebust("res/ui/interactive_tutorial.noinline/" + hintId + ".gif") + "')"; "url('res/ui/interactive_tutorial.noinline/" + hintId + ".gif')";
this.element.classList.toggle("animEven"); this.element.classList.toggle("animEven");
this.element.classList.toggle("animOdd"); this.element.classList.toggle("animOdd");
if (hintId) { if (hintId) {

View File

@ -1,5 +1,4 @@
import { MusicInstanceInterface, SoundInstanceInterface, SoundInterface, MUSIC, SOUNDS } from "../sound"; import { MusicInstanceInterface, SoundInstanceInterface, SoundInterface, MUSIC, SOUNDS } from "../sound";
import { cachebust } from "../../core/cachebust";
import { createLogger } from "../../core/logging"; import { createLogger } from "../../core/logging";
import { globalConfig } from "../../core/config"; import { globalConfig } from "../../core/config";
@ -23,7 +22,7 @@ class SoundSpritesContainer {
} }
return (this.loadingPromise = new Promise(resolve => { return (this.loadingPromise = new Promise(resolve => {
this.howl = new Howl({ this.howl = new Howl({
src: cachebust("res/sounds/sfx.mp3"), src: "res/sounds/sfx.mp3",
sprite: sprites.sprite, sprite: sprites.sprite,
autoplay: false, autoplay: false,
loop: false, loop: false,
@ -95,7 +94,7 @@ class MusicInstance extends MusicInstanceInterface {
load() { load() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.howl = new Howl({ this.howl = new Howl({
src: cachebust("res/sounds/music/" + this.url + ".mp3"), src: "res/sounds/music/" + this.url + ".mp3",
autoplay: false, autoplay: false,
loop: true, loop: true,
html5: true, html5: true,

View File

@ -1,7 +1,6 @@
import { TextualGameState } from "../core/textual_game_state"; import { TextualGameState } from "../core/textual_game_state";
import { T } from "../translations"; import { T } from "../translations";
import { THIRDPARTY_URLS } from "../core/config"; import { THIRDPARTY_URLS } from "../core/config";
import { cachebust } from "../core/cachebust";
import { getLogoSprite } from "../core/utils"; import { getLogoSprite } from "../core/utils";
export class AboutState extends TextualGameState { export class AboutState extends TextualGameState {
@ -16,7 +15,7 @@ export class AboutState extends TextualGameState {
getMainContentHTML() { getMainContentHTML() {
return ` return `
<div class="head"> <div class="head">
<img src="${cachebust("res/" + getLogoSprite())}" alt="shapez.io Logo"> <img src="res/${getLogoSprite()}" alt="shapez.io Logo">
</div> </div>
<div class="text"> <div class="text">
${T.about.body ${T.about.body

View File

@ -1,4 +1,3 @@
import { cachebust } from "../core/cachebust";
import { globalConfig, THIRDPARTY_URLS } from "../core/config"; import { globalConfig, THIRDPARTY_URLS } from "../core/config";
import { GameState } from "../core/game_state"; import { GameState } from "../core/game_state";
import { DialogWithForm } from "../core/modal_dialog_elements"; import { DialogWithForm } from "../core/modal_dialog_elements";
@ -43,11 +42,11 @@ export class MainMenuState extends GameState {
</div> </div>
<video autoplay muted loop class="fullscreenBackgroundVideo"> <video autoplay muted loop class="fullscreenBackgroundVideo">
<source src="${cachebust("res/bg_render.webm")}" type="video/webm"> <source src="res/bg_render.webm" type="video/webm">
</video> </video>
<div class="logo"> <div class="logo">
<img src="${cachebust("res/" + getLogoSprite())}" alt="shapez.io Logo" <img src="res/${getLogoSprite()}" alt="shapez.io Logo"
width="${Math.round((710 / 3) * this.app.getEffectiveUiScale())}" width="${Math.round((710 / 3) * this.app.getEffectiveUiScale())}"
height="${Math.round((180 / 3) * this.app.getEffectiveUiScale())}" height="${Math.round((180 / 3) * this.app.getEffectiveUiScale())}"
> >
@ -132,7 +131,7 @@ export class MainMenuState extends GameState {
<div class="author"> <div class="author">
<a class="producerLink" href="https://tobspr.io" target="_blank" title="tobspr Games" rel="follow"> <a class="producerLink" href="https://tobspr.io" target="_blank" title="tobspr Games" rel="follow">
<img src="${cachebust("res/logo-tobspr-games.svg")}" alt="tobspr Games" <img src="res/logo-tobspr-games.svg" alt="tobspr Games"
height="${25 * 0.8 * this.app.getEffectiveUiScale()}" height="${25 * 0.8 * this.app.getEffectiveUiScale()}"
width="${82 * 0.8 * this.app.getEffectiveUiScale()}" width="${82 * 0.8 * this.app.getEffectiveUiScale()}"
> >

View File

@ -1,4 +1,3 @@
import { cachebust } from "../core/cachebust";
import { GameState } from "../core/game_state"; import { GameState } from "../core/game_state";
export class MobileWarningState extends GameState { export class MobileWarningState extends GameState {
@ -9,7 +8,7 @@ export class MobileWarningState extends GameState {
getInnerHTML() { getInnerHTML() {
return ` return `
<img class="logo" src="${cachebust("res/logo.png")}" alt="shapez.io Logo"> <img class="logo" src="res/logo.png" alt="shapez.io Logo">
<p>I'm sorry, but shapez.io is not available on mobile devices yet!</p> <p>I'm sorry, but shapez.io is not available on mobile devices yet!</p>
<p>If you have a desktop device, you can get shapez on Steam:</p> <p>If you have a desktop device, you can get shapez on Steam:</p>
@ -27,18 +26,6 @@ export class MobileWarningState extends GameState {
return false; return false;
} }
onEnter() {
try {
if (window.gtag) {
window.gtag("event", "click", {
event_category: "ui",
event_label: "mobile_warning",
});
}
} catch (ex) {
console.warn("Failed to track mobile click:", ex);
}
}
onLeave() { onLeave() {
// this.dialogs.cleanup(); // this.dialogs.cleanup();
} }

View File

@ -1,5 +1,4 @@
import { CHANGELOG } from "../changelog"; import { CHANGELOG } from "../changelog";
import { cachebust } from "../core/cachebust";
import { globalConfig } from "../core/config"; import { globalConfig } from "../core/config";
import { GameState } from "../core/game_state"; import { GameState } from "../core/game_state";
import { createLogger } from "../core/logging"; import { createLogger } from "../core/logging";
@ -283,7 +282,7 @@ export class PreloadState extends GameState {
subElement.innerHTML = ` subElement.innerHTML = `
<div class="logo"> <div class="logo">
<img src="${cachebust("res/" + getLogoSprite())}" alt="Shapez.io Logo"> <img src="res/getLogoSprite()" alt="Shapez.io Logo">
</div> </div>
<div class="failureInner"> <div class="failureInner">
<div class="errorHeader"> <div class="errorHeader">