-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6cec7e
commit 0efb472
Showing
13 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/* /index.html 200 |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"registerType": "prompt", | ||
"name": "E-Commercew", | ||
"short_name": "E-Commerce", | ||
"description": "Effortless online shopping: curated collections, easy cart & wishlist, detailed descriptions, intuitive interface. Shop smarter today.", | ||
"start_url": "/", | ||
"scope": "/", | ||
"display": "standalone", | ||
"orientation": "any", | ||
"theme_color": "#181818", | ||
"background_color": "#181818", | ||
"icons": [ | ||
{ | ||
"src": "/android-chrome-192x192.webp", | ||
"sizes": "192x192", | ||
"type": "image/webp" | ||
}, | ||
{ | ||
"src": "/android-chrome-512x512.webp", | ||
"sizes": "512x512", | ||
"type": "image/webp" | ||
}, | ||
{ | ||
"src": "/apple-touch-icon.webp", | ||
"sizes": "180x180", | ||
"type": "image/webp" | ||
}, | ||
{ | ||
"src": "/android-chrome-512x512.webp", | ||
"sizes": "512x512", | ||
"type": "image/webp", | ||
"purpose": "maskable" | ||
}, | ||
{ | ||
"src": "/android-chrome-512x512.png", | ||
"sizes": "512x512", | ||
"type": "image/png" | ||
} | ||
], | ||
"screenshots": [ | ||
{ | ||
"src": "/install-pwa-image.webp", | ||
"sizes": "1897x861", | ||
"type": "image/webp", | ||
"form_factor": "wide", | ||
"label": "Wonder Widgets" | ||
}, | ||
{ | ||
"src": "/install-pwa-mobile.webp", | ||
"sizes": "462x728", | ||
"type": "image/webp", | ||
"form_factor": "narrow", | ||
"label": "Wonder Widgets" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export async function register() { | ||
if ("serviceWorker" in navigator) { | ||
try { | ||
const registration = await navigator.serviceWorker.register("./sw.js"); | ||
|
||
// console.log("serviceWorker registered", registration); | ||
} catch (e) { | ||
console.log("failed to register serviceWorker", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
"use strict"; | ||
|
||
// Variables | ||
const CACHE_NAME = "e-commerce-v8"; | ||
const ASSETS = ["/", "/index.html"]; | ||
|
||
// Functions | ||
async function cacheAssets() { | ||
const cache = await caches.open(CACHE_NAME); | ||
await cache.addAll(ASSETS); | ||
} | ||
|
||
async function handleFetchAndCache(request) { | ||
const cacheResponse = await caches.match(request); | ||
|
||
const networkResponse = fetch(request) | ||
.then(async (networkRes) => { | ||
const shouldSkipCache = networkRes.url.includes("chrome-extension"); | ||
|
||
if (shouldSkipCache) return networkRes; | ||
|
||
if (networkRes.ok) { | ||
const cache = await caches.open(CACHE_NAME); | ||
await cache.put(request, networkRes.clone()); | ||
} | ||
|
||
return networkRes; | ||
}) | ||
.catch((err) => { | ||
console.error("Fetch failed:", err); | ||
}); | ||
|
||
return cacheResponse || networkResponse; | ||
} | ||
|
||
async function updateCachedAssets() { | ||
const cache = await caches.open(CACHE_NAME); | ||
|
||
try { | ||
const responses = await Promise.all( | ||
ASSETS.map(async (asset) => { | ||
const fetchedResponse = await fetch(asset); | ||
|
||
if (fetchedResponse.ok) { | ||
await cache.put(asset, fetchedResponse.clone()); | ||
} | ||
|
||
return fetchedResponse; | ||
}) | ||
); | ||
|
||
const cacheKeys = await caches.keys(); | ||
await Promise.all( | ||
cacheKeys | ||
.filter((key) => key !== CACHE_NAME) | ||
.map((key) => caches.delete(key)) | ||
); | ||
|
||
return responses; | ||
} catch (error) { | ||
console.error("Failed to update cache:", error); | ||
} | ||
} | ||
|
||
function handleFetchEvent(event) { | ||
const isGetMethod = event.request.method === "GET"; | ||
|
||
event.respondWith(handleFetchAndCache(event.request)); | ||
|
||
if (isGetMethod) { | ||
event.waitUntil(updateCachedAssets()); | ||
} | ||
} | ||
|
||
// Events | ||
self.addEventListener("install", (event) => event.waitUntil(cacheAssets())); | ||
self.addEventListener("activate", (event) => | ||
event.waitUntil(updateCachedAssets()) | ||
); | ||
self.addEventListener("fetch", handleFetchEvent); |