-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CacheStorage and ContentIndex readme examples
- Loading branch information
1 parent
cbe18d2
commit 156678a
Showing
8 changed files
with
107 additions
and
8 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
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
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,12 @@ | ||
import { caches } from "@virtualstate/internal"; | ||
|
||
const cache = await caches.open("cache"); | ||
|
||
const url = "https://example.com"; | ||
|
||
await cache.add(url); | ||
|
||
const response = await cache.match(url); | ||
const text = await response.text(); | ||
|
||
console.log(response.status, text.substring(0, 15), text.length); // 200 "<!doctype html>"; |
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,28 @@ | ||
import { index, caches } from "@virtualstate/internal"; | ||
|
||
const entry = { | ||
id: "post-1", | ||
url: "/posts/amet.html", | ||
title: "Amet consectetur adipisicing", | ||
description: | ||
"Repellat et quia iste possimus ducimus aliquid a aut eaque nostrum.", | ||
icons: [ | ||
{ | ||
src: "https://javascript.org.nz/logo.png", | ||
sizes: "128x128", | ||
type: "image/png", | ||
}, | ||
], | ||
category: "article", | ||
}; | ||
await index.add(entry); | ||
|
||
console.log(await index.getAll()) // [{ id: "post-1" }] | ||
|
||
const cache = await caches.open("contentIndex"); | ||
|
||
for (const { src } of entry.icons) { | ||
const response = await cache.match(src); | ||
const { byteLength } = await response.arrayBuffer(); | ||
console.log(src, response.status, byteLength) // ... 200 5348 | ||
} |
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,5 @@ | ||
export {} | ||
|
||
await import("./worker/main.js"); | ||
await import("./cache/cache.js"); | ||
await import("./content-index/index.js"); |
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
File renamed without changes.
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