Skip to content

Commit c9f5303

Browse files
authored
relative paths
adjusted caching issues
1 parent 6afdce2 commit c9f5303

File tree

3 files changed

+75
-8
lines changed

3 files changed

+75
-8
lines changed

marble_webapp/index.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,34 @@
1818
<canvas id="gameCanvas"></canvas>
1919
<div id="ui-overlay">
2020
<div id="win-message" class="hidden">
21-
<h2>You Won!</h2>
22-
<button id="play-again-btn">Play Again</button>
21+
<h2>Gewonnen</h2>
22+
<button id="play-again-btn">Nochmal</button>
2323
</div>
2424
</div>
2525
</div>
2626

2727
<div id="controls">
28-
<button id="resetTiltBtn">Reset Tilt</button>
28+
<button id="resetTiltBtn">zurücksetzen</button>
2929
<div class="slider-container">
30-
<label for="sensitivitySlider">Sensitivity</label>
30+
<label for="sensitivitySlider">Empfindlichkeit</label>
3131
<input type="range" id="sensitivitySlider" min="0.1" max="1.5" step="0.05" value="0.5">
3232
</div>
3333
</div>
3434

35-
<script>
35+
36+
<script>
3637
// Register Service Worker for offline functionality
3738
if ('serviceWorker' in navigator) {
3839
window.addEventListener('load', () => {
39-
navigator.serviceWorker.register('/sw.js')
40-
.then(registration => console.log('ServiceWorker registration successful'))
40+
// Corrected path: 'sw.js' is in the same directory as index.html
41+
navigator.serviceWorker.register('sw.js')
42+
.then(registration => console.log('ServiceWorker registration successful. Scope: ', registration.scope))
4143
.catch(err => console.log('ServiceWorker registration failed: ', err));
4244
});
4345
}
4446
</script>
4547
<script src="app.js" type="module"></script>
48+
49+
4650
</body>
4751
</html>

marble_webapp/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Marble Maze",
33
"short_name": "MarbleMaze",
4-
"start_url": "/index.html",
4+
"start_url": ".",
55
"display": "standalone",
66
"background_color": "#333333",
77
"theme_color": "#333333",

marble_webapp/sw.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
// Add all your assets to this list
3+
const CACHE_NAME = 'marble-maze-v2';
4+
// All paths are now relative to the sw.js location
5+
const URLS_TO_CACHE = [
6+
'.', // Caches the subfolder's root (e.g., /marble_webapp/)
7+
'index.html',
8+
'style.css',
9+
'app.js',
10+
'manifest.json',
11+
'assets/background.jpg',
12+
'assets/marble.png',
13+
'assets/hole.png',
14+
'assets/goal.png',
15+
'assets/icon-192.png',
16+
'assets/icon-512.png'
17+
];
18+
19+
self.addEventListener('install', event => {
20+
event.waitUntil(
21+
caches.open(CACHE_NAME)
22+
.then(cache => {
23+
console.log('Opened cache');
24+
return cache.addAll(URLS_TO_CACHE);
25+
})
26+
);
27+
});
28+
29+
self.addEventListener('fetch', event => {
30+
event.respondWith(
31+
caches.match(event.request)
32+
.then(response => {
33+
if (response) {
34+
return response;
35+
}
36+
return fetch(event.request);
37+
})
38+
);
39+
});
40+
41+
self.addEventListener('install', event => {
42+
event.waitUntil(
43+
caches.open(CACHE_NAME)
44+
.then(cache => {
45+
console.log('Opened cache');
46+
return cache.addAll(URLS_TO_CACHE);
47+
})
48+
);
49+
});
50+
51+
self.addEventListener('fetch', event => {
52+
event.respondWith(
53+
caches.match(event.request)
54+
.then(response => {
55+
// Cache hit - return response
56+
if (response) {
57+
return response;
58+
}
59+
// Not in cache - fetch from network
60+
return fetch(event.request);
61+
})
62+
);
63+
});

0 commit comments

Comments
 (0)