-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
demo: service worker for offline access #41
Conversation
Codecov Report
@@ Coverage Diff @@
## main #41 +/- ##
==========================================
- Coverage 93.08% 83.49% -9.59%
==========================================
Files 21 60 +39
Lines 680 1818 +1138
Branches 123 361 +238
==========================================
+ Hits 633 1518 +885
- Misses 28 251 +223
- Partials 19 49 +30
Flags with carried forward coverage won't be shown. Click here to find out more. see 57 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
demo/src/service-worker.ts
Outdated
event.waitUntil( | ||
(async () => { | ||
await self.clients.claim(); | ||
for (const key of await caches.keys()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If caches
allows it, you could delete all deprecated caches in parallel:
await Promise.all((await caches.keys()).filter((key) => key !== CACHE).map((key) => caches.delete(key)));
demo/scripts/copySamples.plugin.ts
Outdated
}); | ||
for (const file of files) { | ||
const name = path.posix.join(dst, file); | ||
console.log(name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use instead a logger created using vite createLogger
utility.
demo/src/service-worker.ts
Outdated
const cache = await caches.open(CACHE); | ||
const {withHash, withoutHash} = splitAssets(ASSETS); | ||
const missingWithHash: string[] = []; | ||
for (const url of withHash) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe could be written as the following:
await Promise.all(
withHash.map((url) =>
caches.match(url).then((response) => {
if (response?.ok) {
cache.put(url, response);
} else {
missingWithHash.push(url);
}
})
)
);
Not sure of the gain however.
@quentinderoubaix Thank you for your good suggestions. I have added commit e36e1f1 to implement these changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM !
@quentinderoubaix Thank you for your review! |
No description provided.