Add cache busting
parent
814eb3053e
commit
eb6ee79b3e
|
@ -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": [
|
||||
{
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue