/
index.html
52 lines (47 loc) · 1.94 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<html>
<head>
<title>Example for Phaser cache Buster</title>
<!-- Include Phaser cache Buster JS -->
<script type="text/javascript" src="../node_modules/phaser/dist/phaser.js"></script>
<script type="text/javascript" src="../build/phaser-cachebuster.min.js"></script>
<style>
body {
margin: 0 auto;
padding: 0;
}
</style>
<script type="text/javascript">
/**
* Small funcion that allows use to load javascript files with a query parameter for cachebusting
*
* @param src The file we'd like to load
* @param buster The version used for cache busting, this will be appended to the url
* @param callback A function that will be called (if supplied) once the file has been loaded
*/
function addScript(src, buster, callback) {
var s = document.createElement('script');
s.setAttribute('src', src + '?v=' + buster);
if (typeof callback === 'function') {
s.onload = callback;
}
document.body.appendChild(s);
}
</script>
</head>
<body>
<script type="text/javascript">
//This piece of code needs to be loaded from the body, otherwise its not available to append the script locations
//First we load version.js dynamicly, and append the current date (to the milisecond) as a query string.
addScript('version.js', Date.now(), function() {
//This function gets called when version.js is loaded, and thus var version is available for us to use
console.log('Version was loaded with version number: ' + version);
//Now load the game script and use the version as a cachebusting query string
addScript('game.js', version, function () {
//Game is now loaded, will be automaticly started
console.log('Game has been loaded');
});
});
</script>
</body>
</html>