Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Service Worker & Workbox

Service Worker & Workbox

standalone service worker for the frontend caching

Drupal Ahmedabad

September 26, 2023
Tweet

More Decks by Drupal Ahmedabad

Other Decks in Programming

Transcript

  1. Agenda • What are Service Workers • What is Workbox

    • Workbox - Strategies • Project Implementation • Questions 2
  2. Service Workers • Service workers are specialized JavaScript assets that

    act as proxies between web browsers and web servers. They aim to improve reliability by providing offline access, as well as boost page performance. • Used to improve performance for slow network connections. 3
  3. Service Workers • Cached every assets for e.g. images, JS

    / CSS request, font awesome and many more. • It will be terminated when not in use, and restarted when its next needed. 4
  4. Why are we using service workers ? • It is

    Programmable network proxy allowing you to control how network request from your page are handled. • Optimizing JS script execution • Reducing main thread load time 5
  5. Workbox • Workbox is a set of modules that simplify

    common service worker routing and caching. • Each module available addresses a specific aspect of service worker development. 6
  6. Project Implementations • Use the NPM Packages • npm install

    --save-dev workbox-precaching • npm install --save-dev workbox-cli • npm install --save-dev esbuild 11
  7. Project Implementations • Update Package.json - In the build command

    attach this command • esbuild --outfile=sw.js --bundle sw.ts && workbox injectManifest • In this sw.js path should be root of our web application. • Run the command - npm run build 14
  8. 18

  9. 20