Add cache busting

This commit is contained in:
Flashfyre 2024-03-31 23:58:03 -04:00
parent 814eb3053e
commit eb6ee79b3e
3 changed files with 38 additions and 3 deletions

6
package-lock.json generated
View File

@ -2381,9 +2381,9 @@
"dev": true
},
"node_modules/follow-redirects": {
"version": "1.15.5",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz",
"integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==",
"version": "1.15.6",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz",
"integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==",
"dev": true,
"funding": [
{

View File

@ -56,6 +56,7 @@ import PokemonInfoContainer from './ui/pokemon-info-container';
import { biomeDepths } from './data/biomes';
import { initTouchControls } from './touch-controls';
import { UiTheme } from './enums/ui-theme';
import CacheBustedLoaderPlugin from './plugins/cache-busted-loader-plugin';
export const bypassLogin = false;
@ -188,6 +189,8 @@ export default class BattleScene extends Phaser.Scene {
this.phaseQueuePrepend = [];
this.phaseQueuePrependSpliceIndex = -1;
this.nextCommandPhaseQueue = [];
Phaser.Plugins.PluginCache.register('Loader', CacheBustedLoaderPlugin, 'load');
}
loadImage(key: string, folder: string, filename?: string) {
@ -266,6 +269,13 @@ export default class BattleScene extends Phaser.Scene {
}
preload() {
const indexFile = Array.from(document.querySelectorAll('script')).map(s => s.src).find(s => /\/index/.test(s));
if (indexFile) {
const buildIdMatch = /index\-(.*?)\.js$/.exec(indexFile);
if (buildIdMatch)
this.load['cacheBuster'] = buildIdMatch[1];
}
// Load menu images
this.loadAtlas('bg', 'ui');
this.loadImage('command_fight_labels', 'ui');

View File

@ -0,0 +1,25 @@
let cacheBuster = '';
export default class CacheBustedLoaderPlugin extends Phaser.Loader.LoaderPlugin {
constructor(scene: Phaser.Scene) {
super(scene)
}
get cacheBuster() {
return cacheBuster
}
set cacheBuster(version) {
cacheBuster = version
}
addFile(file): void {
if (!Array.isArray(file))
file = [ file ]
if (cacheBuster)
file.forEach(item => item.url += '?v=' + cacheBuster);
super.addFile(file);
}
}