Is it possible to intercept and cache WebSocket messages in Service Worker, like all examples for regular HTTP requests?

I know that you can create WebSocket connections inside the Service Worker itself; my question is, can you really use WebSocket from your application in normal mode and request WebSocket requests to intercept / cache Service Worker in the same way as you can do for regular HTTP fetch requests?

Here's an example of intercepting and caching a regular HTTP request from Service Worker.

self.addEventListener('fetch', function(event) {
  // If a match isn't found in the cache, the response
  // will look like a connection error
  event.respondWith(caches.match(event.request));
});

How to configure Service Worker if all my requests were through WebSockets?

+4
source share
2 answers

-.

fetch HTTPS , message postMessage() .

HTTP- -, fetch, .

+4

, fetch, , .

, -, . .

, .

0

All Articles