Fireship · @fireship

Angular 5 Service Worker - Hacker News PWA

Uploaded November 26, 2017 · Length 7:41

Angular 5 Service Worker - Hacker News PWA

Summary

Angular 5 Service Worker - how to build a PWA with Angular CLI and Firebase

  • angular 5 service worker
  • pwa angular cli
  • firebase hosting
  • progressive web app
  • angular service worker config

Transcript preview

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

  1. 0:00

    just last month angular 5 was released

  2. 0:01

    and with it comes the new serviceworker

  3. 0:04

    module that makes building progressive

  4. 0:05

    web apps easier than ever before all we

  5. 0:08

    need to do is set a few configuration

  6. 0:09

    variables and angular will automatically

  7. 0:11

    generate a serviceworker with our

  8. 0:13

    production build in this video I'm going

  9. 0:15

    to show you how to use the worker to

  10. 0:16

    score 100 on a progressive web app on it

  11. 0:18

    and I'll show you how to customize the

  12. 0:20

    worker to fit the needs of your specific

  13. 0:22

    application I'm going to do this by

  14. 0:24

    creating my own version of hacker news

  15. 0:26

    which is the gold standard for comparing

  16. 0:28

    performance and usability across various

  17. 0:30

    JavaScript frameworks if you're just

  18. 0:32

    finding me for the first time make sure

  19. 0:33

    to subscribe and for this video I have a

  20. 0:36

    full working demo deployed to firebase

  21. 0:37

    hosting feel free to mess around with it

  22. 0:39

    and if you see anything you want to

  23. 0:41

    optimize our fix send me a pull request

  24. 0:43

    on github

  25. 0:44

    before we get going I just want to point

  26. 0:45

    out that service workers aren't

  27. 0:47

    supported on all modern browsers Safari

  28. 0:49

    and Microsoft edge or the main holdouts

  29. 0:51

    but they should be supported in the

  30. 0:52

    future at the time of this video the

  31. 0:54

    serviceworker is only available in that

  32. 0:56

    beta version of the angular CLI so

  33. 0:59

    you'll want to install it with the next

  34. 1:00

    tag and then make sure the version you

  35. 1:03

    have installed is 1.6 or greater and if

  36. 1:06

    you're starting from an existing angular

  37. 1:07

    5 app you can simply create the files

  38. 1:09

    I'm about to show you in the upcoming

  39. 1:10

    steps here to create a new app with the

  40. 1:12

    serviceworker configured automatically

  41. 1:14

    run ng new with the serviceworker flag

  42. 1:17

    then inside that new app the first place

  43. 1:19

    I'm going to go is the angular CLI JSON

  44. 1:22

    file inside here you'll want to add

  45. 1:24

    manifest.json to the assets array we're

  46. 1:27

    going to create this file manually here

  47. 1:29

    in the next step then down here you'll

  48. 1:31

    notice that the serviceworker option is

  49. 1:33

    set to true which tells angular to

  50. 1:35

    generate the serviceworker at Build time

  51. 1:36

    from there you're going to create a web

  52. 1:39

    app manifest in the source directory the

  53. 1:42

    purpose of the manifest is to tell

  54. 1:43

    browsers how to handle your web app

  55. 1:45

    we're just going to set the bare minimum

  56. 1:47

    options for now so we have a start URL

  57. 1:49

    which is just the root and then you'll

  58. 1:51

    need a theme color and background color

  59. 1:53

    then you'll need to add some icons if

  60. 1:55

    you want your app to be installable on

  61. 1:57

    mobile devices the bare minimum is just

  62. 1:59

    a 512 by 512 image but you can add