Skip to content

Commit b7d8348

Browse files
committed
update sw
1 parent 976e08e commit b7d8348

6 files changed

Lines changed: 74 additions & 15 deletions

File tree

README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,20 @@ A versatile collection of web apps designed for developers and creatives on the
2929

3030
<table>
3131
<tr><th width="30%">Web App</th><th>Description</th></tr>
32+
<tr><td width="30%"><img src="app/web-app/ai-chatbot.jpg" width="30%" height="auto" alt="AI-chatbot"></td><td>AI-chatbot<br>AI chatbot with local storage full-featured for Codemo</th></tr>
3233
<tr><td width="30%"><img src="app/web-app/dpaint.webp" width="30%" height="auto" alt="dpaint"></td><td>dpaint<br>Image editor modeled after the legendary Deluxe</td></tr>
33-
<tr><td width="30%"><img src="app/web-app/drawio.webp" width="30%" height="auto" alt="dpaint"></td><td>drawio<br>Diagram editor or whiteboard by JGraph Ltd and draw.io AG</th></tr>
34-
<tr><td width="30%"><img src="app/web-app/encrypt.webp" width="30%" height="auto" alt="dpaint"></td><td>encrypt<br>Static HTML Encryption for public host</th></tr>
35-
<tr><td width="30%"><img src="app/web-app/erd-editor.webp" width="30%" height="auto" alt="dpaint"></td><td>erd-editor<br>Entity-Relationship Diagram Editor by SeungHwan-Lee @dineug</th></tr>
36-
<tr><td width="30%"><img src="app/web-app/godsvg.webp" width="30%" height="auto" alt="dpaint"></td><td>godsvg<br>Editor for Scalable Vector Graphics (SVG) by @MewPurPur</th></tr>
37-
<tr><td width="30%"><img src="app/web-app/grapesjs.webp" width="30%" height="auto" alt="dpaint"></td><td>grapesjs<br>WYSIWYG eeb page builder</th></tr>
38-
<tr><td width="30%"><img src="app/web-app/livecodes.webp" width="30%" height="auto" alt="dpaint"></td><td>livecodes<br>Live code playground</th></tr>
39-
<tr><td width="30%"><img src="app/web-app/mermaid.webp" width="30%" height="auto" alt="dpaint"></td><td>mermaid<br>Charts and diagrams editor</th></tr>
40-
<tr><td width="30%"><img src="app/web-app/tldraw.webp" width="30%" height="auto" alt="dpaint"></td><td>tldraw<br>Canvas and whiteboard draw</th></tr>
41-
<tr><td width="30%"><img src="app/web-app/voxel-builder.webp" width="30%" height="auto" alt="dpaint"></td><td>voxel-builder<br>Voxel-based 3D Modeling Application nimadez</th></tr>
42-
<tr><td width="30%"><img src="app/web-app/vvvebjs.webp" width="30%" height="auto" alt="dpaint"></td><td>vvvebjs<br>Drag and drop web page builder givanz</th></tr>
34+
<tr><td width="30%"><img src="app/web-app/drawio.webp" width="30%" height="auto" alt="drawio"></td><td>drawio<br>Diagram editor or whiteboard by JGraph Ltd and draw.io AG</th></tr>
35+
<tr><td width="30%"><img src="app/web-app/encrypt.webp" width="30%" height="auto" alt="encrypt"></td><td>encrypt<br>Static HTML Encryption for public host</th></tr>
36+
<tr><td width="30%"><img src="app/web-app/erp-editor.webp" width="30%" height="auto" alt="erd-editor"></td><td>erd-editor<br>Entity-Relationship Diagram Editor by SeungHwan-Lee @dineug</th></tr>
37+
<tr><td width="30%"><img src="app/web-app/grapesjs.webp" width="30%" height="auto" alt="grapesjs"></td><td>grapesjs<br>WYSIWYG eeb page builder</th></tr>
38+
<tr><td width="30%"><img src="app/web-app/image-converter.webp" width="30%" height="auto" alt="Image Converter"></td><td>Image Converter<br>Powered by web workers & jSquash image codecs</th></tr>
39+
<tr><td width="30%"><img src="app/web-app/image-optimize.webp" width="30%" height="auto" alt="Image Optimize"></td><td>Image Optimize<br>Optimize images using best-in-class codecs, right in the browser</th></tr>
40+
<tr><td width="30%"><img src="app/web-app/livecodes.webp" width="30%" height="auto" alt="livecodes"></td><td>livecodes<br>Live code playground</th></tr>
41+
<tr><td width="30%"><img src="app/web-app/mermaid.webp" width="30%" height="auto" alt="mermaid"></td><td>mermaid<br>Charts and diagrams editor</th></tr>
42+
<tr><td width="30%"><img src="app/web-app/social-media-agent.webp" width="30%" height="auto" alt="social-media"></td><td>social-media<br>Generate optimized content for all your social media platforms in one click</th></tr>
43+
<tr><td width="30%"><img src="app/web-app/tldraw.webp" width="30%" height="auto" alt="tldraw"></td><td>tldraw<br>Canvas and whiteboard draw</th></tr>
44+
<tr><td width="30%"><img src="app/web-app/voxel-builder.webp" width="30%" height="auto" alt="voxel-builder"></td><td>voxel-builder<br>Voxel-based 3D Modeling Application nimadez</th></tr>
45+
<tr><td width="30%"><img src="app/web-app/vvveb.webp" width="30%" height="auto" alt="vvvebjs"></td><td>vvvebjs<br>Drag and drop web page builder givanz</th></tr>
4346
</table>
4447

4548

app/service-worker.js

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,56 @@ const routes = [
2222
'/codemo/tools/notes/',
2323
];
2424

25-
// combine static files and routes to cache
25+
// exclude routes (use deployment paths). Use trailing '*' to indicate "prefix"
26+
const excludedRoutes = [
27+
'/codemo/web-app/*',
28+
'/codemo/web-app/',
29+
'/web-app/*',
30+
];
31+
32+
// helper: simple pattern matching supporting trailing '*' as a prefix wildcard
33+
const routeMatchesPattern = (pattern, pathname) => {
34+
if (!pattern) return false;
35+
const p = pattern.startsWith('/') ? pattern : '/' + pattern;
36+
const path = pathname.startsWith('/') ? pathname : '/' + pathname;
37+
38+
if (p.endsWith('*')) {
39+
const prefix = p.slice(0, -1);
40+
return path.startsWith(prefix);
41+
}
42+
return path === p;
43+
};
44+
45+
// flexible route exclusion checker:
46+
// - accepts full URL string (request.url), a Request, or a pathname
47+
// - uses prefix matching for patterns that end with '*'
48+
const isRouteExcluded = (input) => {
49+
let pathname;
50+
try {
51+
if (typeof input === 'string') {
52+
// could be full URL or pathname
53+
pathname = (new URL(input, self.location.href)).pathname;
54+
}
55+
else if (input && typeof input.url === 'string') {
56+
pathname = (new URL(input.url, self.location.href)).pathname;
57+
}
58+
else if (input && typeof input.pathname === 'string') {
59+
pathname = input.pathname;
60+
}
61+
else {
62+
return false;
63+
}
64+
} catch (e) {
65+
// fallback: if parsing fails, do not exclude
66+
return false;
67+
}
68+
69+
return excludedRoutes.some(pattern => routeMatchesPattern(pattern, pathname));
70+
};
71+
72+
// combine static files and routes to cache (filter using matcher)
2673
const filesToCache = [
27-
...routes,
74+
...routes.filter(route => !isRouteExcluded(route)),
2875
...staticFiles,
2976
];
3077

@@ -44,6 +91,9 @@ const IDBConfig = {
4491
// returns if the app is offline
4592
const isOffline = () => !self.navigator.onLine;
4693

94+
// (isRouteExcluded defined earlier above filesToCache)
95+
// The exclusion matcher is implemented above and used for both install and fetch-time checks.
96+
4797
// return if a request should be retried when offline, in this example, all POST, PUT, DELETE requests
4898
// and requests that are listed in the requestsToRetryWhenOffline array
4999
// you can adapt this function to your specific needs
@@ -265,13 +315,19 @@ const fetchHandler = async e => {
265315
e.respondWith(
266316
(async () => {
267317
try {
318+
319+
// check if the current route is excluded from caching and handling
320+
if (isRouteExcluded(request.url)) {
321+
return fetch(request);
322+
}
323+
268324
// store requests to IndexedDB that are eligible for retry when offline and return the offline page
269325
// as response so no error is logged
270326
if(isOffline() && isRequestEligibleForRetry(request)) {
271327
console.log('storing request', request);
272328
await storeRequest(request);
273329

274-
return await caches.match('/offline.html');
330+
return await caches.match('/codemo/asset/offline.html');
275331
}
276332

277333
// try to get the response from the cache
@@ -287,8 +343,8 @@ const fetchHandler = async e => {
287343
}
288344
}
289345
catch(err) {
290-
// a fetch error occurred, serve the offline page since we don't have a cached response
291-
return await caches.match('/offline.html');
346+
// a fetch error occurred, serve the offline page since we don't have a cached response
347+
return await caches.match('/codemo/asset/offline.html');
292348
}
293349
})()
294350
);

app/web-app/image-converter.jpg

-39.6 KB
Binary file not shown.

app/web-app/image-converter.webp

11.5 KB
Loading

app/web-app/image-optimize.webp

42.7 KB
Loading
23.6 KB
Loading

0 commit comments

Comments
 (0)