Fireship · @fireship

Progressive Web Apps in 100 Seconds // Build a PWA from Scratch

Uploaded December 16, 2020 · Length 8:10

Progressive Web Apps in 100 Seconds // Build a PWA from Scratch

Summary

Build a progressive web app (PWA) from scratch using Chrome Lighthouse, service workers, and Workbox, covering offline mode, push notifications, and caching.

  • progressive web apps
  • pwa from scratch
  • chrome lighthouse
  • service workers
  • workbox
  • offline mode
  • push notifications
  • caching

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    [Music]

  2. 0:00

    progressive web apps build websites that

  3. 0:02

    deliver an experience indistinguishable

  4. 0:05

    from native mobile apps when smartphones

  5. 0:07

    first hit the scene back in 2008 they

  6. 0:09

    brought with them all kinds of new

  7. 0:10

    features that weren't available on the

  8. 0:12

    web like offline mode push notifications

  9. 0:14

    cameras geolocation and more internet

  10. 0:16

    explorer powered the web back then and

  11. 0:18

    web developers had no way to access most

  12. 0:20

    in-device features in the 2020s though

  13. 0:22

    the game has changed the web platform

  14. 0:24

    has reached near feature parity with

  15. 0:26

    native apps notice how the twitter pwa

  16. 0:28

    can be installed just like a native app

  17. 0:30

    it works without a connection it can

  18. 0:31

    interact with the device camera and

  19. 0:33

    receive push notifications and on top of

  20. 0:35

    that the web offers much better

  21. 0:36

    distribution than app stores and doesn't

  22. 0:38

    take a 30 cut of your revenue not to

  23. 0:40

    mention your app will work on ios

  24. 0:42

    android and the web from a single code

  25. 0:44

    base if you own a website turning it

  26. 0:46

    into a progressive web app is easier

  27. 0:48

    than you might think first open up the

  28. 0:50

    lighthouse tool in chrome dev tools to

  29. 0:52

    run an audit on your site it'll tell you

  30. 0:54

    how well your site performs and what

  31. 0:55

    needs to change to qualify as a pwa at a

  32. 0:58

    bare minimum the site needs to load

  33. 1:00

    quickly and be accessible on mobile most

  34. 1:02

    sites already check this box the more

  35. 1:03

    difficult requirement is making the app

  36. 1:05

    work offline normally a website runs on

  37. 1:08

    a single thread while the tab is open

  38. 1:09

    however modern websites can now register

  39. 1:12

    a service worker which is just a script

  40. 1:14

    that runs in the background it can

  41. 1:15

    perform caching background sync and

  42. 1:18

    listen to push notifications among other

  43. 1:20

    things the implementation is actually

  44. 1:22

    very simple we just check if the browser

  45. 1:23

    supports this feature then register a

  46. 1:25

    javascript file as the worker once

  47. 1:27

    registered you'll find it activated in

  48. 1:29

    the application tab in chrome devtools

  49. 1:31

    from there you can write your own code

  50. 1:33

    in the worker file or use a library like

  51. 1:35

    workbox to do everything for you most

  52. 1:36

    importantly you'll want to cache the

  53. 1:38

    urls in your app so they can be viewed

  54. 1:40

    offline you can inspect the cache and

  55. 1:42

    other background services here in the

  56. 1:43

    application tab the final step is to

  57. 1:45

    create a manifest.json file which

  58. 1:48

    contains icons and other metadata about

  59. 1:50

    the app once the requirements have been

  60. 1:51

    met you'll unlock the pwa achievement

  61. 1:54

    and lighthouse at which point your app

  62. 1:56

    can be installed on most native devices

  63. 1:58

    and can even be listed on google play or