Baseline Widely available *
è¿æ¯ä¼å¨ service worker å
¨å±ä½ç¨åä¸è§¦å fetch
äºä»¶çäºä»¶ç±»åãå®å
å«å
³äº fetch çä¿¡æ¯ï¼å
æ¬ request åæ¥æ¶æ¹å¦ä½å¤çååºãå®æä¾ event.respondWith()
æ¹æ³ï¼å
许æä»¬ä¸ºæ¤ fetch æä¾ä¸ä¸ªååºã
FetchEvent()
å建ä¸ä¸ªæ°ç FetchEvent
对象ãè¿ä¸ªæé 彿°ä¸æ¯å¾å¸¸ç¨ãæµè§å¨èªå·±ä¼å建è¿äºå¯¹è±¡ï¼å¹¶ä¸ºå®ä»¬æä¾ fetch
äºä»¶çåè°ã
ä»å®çç¥å
Event
ç»§æ¿å±æ§ã
FetchEvent.clientId
åªè¯»
FetchEvent.preloadResponse
åªè¯»
ä¸ä¸ªå
ç°ä¸º Response
ç Promise
ï¼å¦æè¯¥ fetch 没æå¯¼èªæè
navigation preload æªå¯ç¨ï¼åæ¯ undefined
ã
FetchEvent.replacesClientId
åªè¯»
FetchEvent.resultingClientId
åªè¯»
FetchEvent.request
åªè¯»
æµè§å¨æ³è¦åéç Request
ã
ä»å®çç¶å
ç´ ExtendableEvent
ç»§æ¿æ¹æ³ã
FetchEvent.respondWith()
黿¢æµè§å¨çé»è®¤ fetch æä½ï¼å¹¶ä¸ç±ä½ èªå·±æä¾ä¸ä¸ªååºï¼å¯ä»¥æ¯ä¸ä¸ª promiseï¼ã
ExtendableEvent.waitUntil()
å»¶é¿äºä»¶ççå½å¨æãç¨äºéç¥æµè§å¨å»¶é¿è¶ åºååºå夿¶é´çä»»å¡ï¼ä¾å¦æµåç¼åã
fetch äºä»¶å¯¹é GET 请æ±ä½¿ç¨æµè§å¨é»è®¤å¼ãå¯¹äº GET 请æ±å®è¯å¾å¨ç¼åä¸å¹é ï¼å¦æç¼å䏿²¡æå¹é ï¼ååè½å°ç½ç»è¯·æ±ã妿å¨ç¼åä¸å¹é æåï¼å®å°å¼æ¥æ´æ°ç¼åï¼ä»¥ä¾ä¸æ¬¡ä½¿ç¨ã
self.addEventListener("fetch", (event) => {
// Let the browser do its default thing
// for non-GET requests.
if (event.request.method !== "GET") return;
// Prevent the default, and handle the request ourselves.
event.respondWith(
(async () => {
// Try to get the response from a cache.
const cache = await caches.open("dynamic-v1");
const cachedResponse = await cache.match(event.request);
if (cachedResponse) {
// If we found a match in the cache, return it, but also
// update the entry in the cache in the background.
event.waitUntil(cache.add(event.request));
return cachedResponse;
}
// If we didn't find a match in the cache, use the network.
return fetch(event.request);
})(),
);
});
è§è æµè§å¨å
¼å®¹æ§ åè§
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4