@3cr/viewer-browser 0.0.133 → 0.0.134
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/playground/index.html +25 -0
- package/playground/sw.js +24 -0
package/package.json
CHANGED
package/playground/index.html
CHANGED
|
@@ -5,16 +5,41 @@
|
|
|
5
5
|
<meta charset="UTF-8" />
|
|
6
6
|
<link rel="icon" href="/favicon.ico" />
|
|
7
7
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
8
|
+
<script type="module">
|
|
9
|
+
function initServiceWorker() {
|
|
10
|
+
// Only enable service worker in production
|
|
11
|
+
if ("serviceWorker" in navigator) {
|
|
12
|
+
navigator.serviceWorker
|
|
13
|
+
.register("/sw.js", { scope: "/" })
|
|
14
|
+
.then((registration) => {
|
|
15
|
+
console.log(
|
|
16
|
+
"[CHECK]: Service_Worker_Registered_With_Scope",
|
|
17
|
+
registration.scope
|
|
18
|
+
);
|
|
19
|
+
})
|
|
20
|
+
.catch((error) => {
|
|
21
|
+
console.error("[ERR]: Service_Worker_Registration_Failed:", error);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Call the initServiceWorker function when the page loads
|
|
27
|
+
window.addEventListener("load", () => {
|
|
28
|
+
initServiceWorker();
|
|
29
|
+
});
|
|
30
|
+
</script>
|
|
8
31
|
<script src="https://cdn.jsdelivr.net/npm/@3cr/viewer-browser@{{version}}/dist/Viewer3CR.umd.js"> </script>
|
|
9
32
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
|
|
10
33
|
<link href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" rel="stylesheet">
|
|
11
34
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
12
35
|
<title>3CR Viewer Playground</title>
|
|
36
|
+
|
|
13
37
|
</head>
|
|
14
38
|
|
|
15
39
|
<body>
|
|
16
40
|
<div id="app"></div>
|
|
17
41
|
<script type="module">
|
|
42
|
+
|
|
18
43
|
window.registerViewer('1.0.0').then(() => {
|
|
19
44
|
window.loadViewer().then()
|
|
20
45
|
})
|
package/playground/sw.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
self.addEventListener("fetch", (event) => {
|
|
2
|
+
event.respondWith(handleServerRequest(event.request));
|
|
3
|
+
});
|
|
4
|
+
|
|
5
|
+
async function handleServerRequest(request) {
|
|
6
|
+
// Define the name for the cache related to GeoServer requests
|
|
7
|
+
const cacheName = "playground-cache";
|
|
8
|
+
// Open or create the cache
|
|
9
|
+
const cache = await caches.open(cacheName);
|
|
10
|
+
|
|
11
|
+
// Try to find the response in the cache
|
|
12
|
+
const cachedResponse = await cache.match(request);
|
|
13
|
+
if (cachedResponse) {
|
|
14
|
+
console.log("[CHECK]: Serving_From_Cache:", request.url);
|
|
15
|
+
return cachedResponse; // If found in cache, return the cached response
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
console.log("[CHECK]: Cache_Miss! Fetching_From_Network:", request.url);
|
|
19
|
+
// If not in cache, fetch from the network
|
|
20
|
+
const networkResponse = await fetch(request);
|
|
21
|
+
// Save the fetched response in the cache for future use
|
|
22
|
+
cache.put(request, networkResponse.clone());
|
|
23
|
+
return networkResponse; // Return the fetched response
|
|
24
|
+
}
|