1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-11 09:11:50 +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

@ -31,12 +31,4 @@ export function getTag() {
export function getVersion() {
// Use the version number specified in package.json
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 { getRevision, cachebust } from "./buildutils.js";
import { getRevision } from "./buildutils.js";
import gulpPostcss from "gulp-postcss";
import postcssAssets from "postcss-assets";
@ -16,21 +16,15 @@ import gulpRename from "gulp-rename";
export default function gulptasksCSS(gulp, buildFolder, browserSync) {
// The assets plugin copies the files
const commitHash = getRevision();
const postcssAssetsPlugin = enableCachebust =>
postcssAssets({
loadPaths: [path.join(buildFolder, "res", "ui")],
basePath: buildFolder,
baseUrl: ".",
cachebuster: enableCachebust
? (filePath, urlPathname) => ({
pathname: cachebust(urlPathname, commitHash),
})
: "",
});
const postcssAssetsPlugin = postcssAssets({
loadPaths: [path.join(buildFolder, "res", "ui")],
basePath: buildFolder,
baseUrl: ".",
});
// Postcss configuration
const postcssPlugins = (prod, { cachebust = false }) => {
const plugins = [postcssAssetsPlugin(cachebust)];
const postcssPlugins = prod => {
const plugins = [postcssAssetsPlugin];
if (prod) {
plugins.unshift(
postcssPresetEnv({
@ -69,7 +63,7 @@ export default function gulptasksCSS(gulp, buildFolder, browserSync) {
.pipe(gulpSassLint.failOnError());
});
function resourcesTask({ cachebust, isProd }) {
function resourcesTask({ isProd }) {
return gulp
.src("../src/css/main.scss")
.pipe(gulpPlumber())
@ -82,27 +76,22 @@ export default function gulptasksCSS(gulp, buildFolder, browserSync) {
])
)
.pipe(gulpRename("async-resources.css"))
.pipe(gulpPostcss(postcssPlugins(isProd, { cachebust })))
.pipe(gulpPostcss(postcssPlugins(isProd)))
.pipe(gulp.dest(buildFolder))
.pipe(browserSync.stream());
}
// Builds the css resources
gulp.task("css.resources.dev", () => {
return resourcesTask({ cachebust: false, isProd: false });
return resourcesTask({ isProd: false });
});
// Builds the css resources in prod (=minified)
gulp.task("css.resources.prod", () => {
return resourcesTask({ cachebust: true, isProd: true });
return resourcesTask({ isProd: true });
});
// Builds the css resources in prod (=minified), without cachebusting
gulp.task("css.resources.prod-standalone", () => {
return resourcesTask({ cachebust: false, isProd: true });
});
function mainTask({ cachebust, isProd }) {
function mainTask({ isProd }) {
return gulp
.src("../src/css/main.scss")
.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(browserSync.stream());
}
// Builds the css main
gulp.task("css.main.dev", () => {
return mainTask({ cachebust: false, isProd: false });
return mainTask({ isProd: false });
});
// Builds the css main in prod (=minified)
gulp.task("css.main.prod", () => {
return mainTask({ cachebust: true, isProd: true });
});
// Builds the css main in prod (=minified), without cachebusting
gulp.task("css.main.prod-standalone", () => {
return mainTask({ cachebust: false, isProd: true });
return mainTask({ isProd: true });
});
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-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 + ".all",
gulp.series(buildName + ".resourcesAndCode", "css.prod-standalone", "html.prod")
);
gulp.task(buildName + ".all", gulp.series(buildName + ".resourcesAndCode", "css.prod", "html.prod"));
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 { T } from "../translations";
import { AtlasDefinition, atlasFiles } from "./atlas_definitions";
import { cachebust } from "./cachebust";
import { Loader } from "./loader";
import { createLogger } from "./logging";
import { Signal } from "./signal";
@ -200,8 +199,7 @@ export class BackgroundResourcesLoader {
const xhr = new XMLHttpRequest();
let notifiedNotComputable = false;
const fullUrl = cachebust(src);
xhr.open("GET", fullUrl, true);
xhr.open("GET", src, true);
xhr.responseType = "arraybuffer";
xhr.onprogress = function (ev) {
if (ev.lengthComputable) {
@ -225,7 +223,7 @@ export class BackgroundResourcesLoader {
xhr.onloadend = function () {
if (!xhr.status.toString().match(/^2/)) {
reject(fullUrl + ": " + xhr.status + " " + xhr.statusText);
reject(src + ": " + xhr.status + " " + xhr.statusText);
} else {
if (!notifiedNotComputable) {
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 { AtlasSprite, BaseSprite, RegularSprite, SpriteAtlasLink } from "./sprites";
import { cachebust } from "./cachebust";
import { createLogger } from "./logging";
/**

View File

@ -4,7 +4,6 @@ import { GameRoot } from "../../root";
import { MinerComponent } from "../../components/miner";
import { DynamicDomAttach } from "../dynamic_dom_attach";
import { TrackedState } from "../../../core/tracked_state";
import { cachebust } from "../../../core/cachebust";
import { T } from "../../../translations";
import { enumItemProcessorTypes, ItemProcessorComponent } from "../../components/item_processor";
import { ShapeItem } from "../../items/shape_item";
@ -190,7 +189,7 @@ export class HUDInteractiveTutorial extends BaseHUDPart {
document.documentElement.setAttribute("data-tutorial-step", hintId);
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("animOdd");
if (hintId) {

View File

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

View File

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

View File

@ -1,4 +1,3 @@
import { cachebust } from "../core/cachebust";
import { globalConfig, THIRDPARTY_URLS } from "../core/config";
import { GameState } from "../core/game_state";
import { DialogWithForm } from "../core/modal_dialog_elements";
@ -43,11 +42,11 @@ export class MainMenuState extends GameState {
</div>
<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>
<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())}"
height="${Math.round((180 / 3) * this.app.getEffectiveUiScale())}"
>
@ -132,7 +131,7 @@ export class MainMenuState extends GameState {
<div class="author">
<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()}"
width="${82 * 0.8 * this.app.getEffectiveUiScale()}"
>

View File

@ -1,4 +1,3 @@
import { cachebust } from "../core/cachebust";
import { GameState } from "../core/game_state";
export class MobileWarningState extends GameState {
@ -9,7 +8,7 @@ export class MobileWarningState extends GameState {
getInnerHTML() {
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>If you have a desktop device, you can get shapez on Steam:</p>
@ -27,18 +26,6 @@ export class MobileWarningState extends GameState {
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() {
// this.dialogs.cleanup();
}

View File

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