Skip to content

Much needed example code for PWA mode using 'InjectManifest' and custom-service-worker.js #9054

Discussion options

You must be logged in to vote

In case if anyone needs it in future, below is the basic setup code for 'custom-service-worker.js' file.

/* eslint-disable */
import {precacheAndRoute} from 'workbox-precaching';
import {clientsClaim} from 'workbox-core';
import {registerRoute} from 'workbox-routing';
import {ExpirationPlugin} from 'workbox-expiration';
import {CacheFirst, StaleWhileRevalidate, NetworkFirst} from 'workbox-strategies';
import {CacheableResponsePlugin} from 'workbox-cacheable-response';

precacheAndRoute(self.__WB_MANIFEST, {})
clientsClaim();

// testing
registerRoute(
        /^https:\/\/.(?:png|gif|jpg|jpeg|svg)$/,
        new CacheFirst({
            cacheName: 'my-img',
            plugins: [
         …

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jitendra1607
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by jitendra1607
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants