'Angular 12 anchor bypass service worker
Im trying to implement a service worker with fetch event like this.
self.onfetch = event => {
const req = event.request;
if (req.method !== 'GET') return;
const url = new URL(req.url);
const dlmatch = DOWNLOAD_URL.exec(url.pathname);
if (dlmatch) {
event.respondWith(decryptStream(dlmatch[1]));
} else if (cacheable(url.pathname)) {
event.respondWith(cachedOrFetched(req));
}
};
The fetch event works fine if I use
fetch() or HttpClient but not when o using anchors. It Always bypass The service worker. Any suggestions?
const a = document.createElement('a');
a.href = downloadUrl;
document.body.appendChild(a);
a.click();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
