Skip to content

Commit

Permalink
pwatest
Browse files Browse the repository at this point in the history
  • Loading branch information
bit-turtle authored Nov 1, 2024
1 parent 86b6b9d commit 9078ba3
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ <h2>Try these games and other things</h2>
<b>Other Things</b>
<br>
<ul>
<li>[New!] <a href="pwatest.html">PWA Test</a></li>
<li>[New!] <a href="maze.html">Maze Generator</a></li>
<li><a href="windowbounce.html">Bouncing Window</a></li>
<li><a href="bounce.html">Ball Bouncing Simulator</a></li>
Expand Down
61 changes: 61 additions & 0 deletions pwatest.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html>
<head>

<!-- Responsive -->
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width,
initial-scale=1">
<meta http-equiv="X-UA-Compatible"
content="ie=edge">

<!-- Title -->
<title>PWA Tutorial</title>

<!-- Meta Tags required for
Progressive Web App -->
<meta name=
"apple-mobile-web-app-status-bar"
content="#aa7700">
<meta name="theme-color"
content="black">

<!-- Manifest File link -->
<link rel="manifest"
href="pwatest.manifest.json">
</head>

<body>
<h1>PWA Test</h1>


<p>
Progressive Web Apps can be installed as an app. This page is one.
</p>


<script>
window.addEventListener('load', () => {
registerSW();
});

// Register the Service Worker
async function registerSW() {
if ('serviceWorker' in navigator) {
try {
await navigator
.serviceWorker
.register('pwatest.service.js');
}
catch (e) {
window.alert('Failed To Register Service Worker: ' + e);
}
}
else {
window.alert("Service Workers Not Supported In Browser");
}
}
</script>
</body>
</html>
17 changes: 17 additions & 0 deletions pwatest.manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name":"PWA Test",
"short_name":"PWA",
"start_url":"pwatest.html",
"display":"standalone",
"background_color":"#5900b3",
"theme_color":"black",
"scope": ".",
"description":"Tests out PWAs.",
"icons":[
{
"src":"turtle.png",
"sizes":"250x250",
"type":"image/png"
}
]
}
19 changes: 19 additions & 0 deletions pwatest.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var staticCacheName = "pwa";

self.addEventListener("install", function (e) {
e.waitUntil(
caches.open(staticCacheName).then(function (cache) {
return cache.addAll(["/", "/pwatest.html"]);
})
);
});

self.addEventListener("fetch", function (event) {
console.log(event.request.url);

event.respondWith(
caches.match(event.request).then(function (response) {
return response || fetch(event.request);
})
);
});
Binary file added turtle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9078ba3

Please sign in to comment.