Fireship · @fireship

Angular Universal on Cloud Functions or AppEngine

Uploaded January 23, 2019 · Length 11:29

Angular Universal on Cloud Functions or AppEngine

Summary

Learn how to server-side render an Angular app and deploy it to Google App Engine or Firebase Cloud Functions.

  • angular universal
  • server-side rendering
  • angular deployment
  • google app engine
  • firebase cloud functions

Transcript preview

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

  1. 0:00

    [Music]

  2. 0:06

    one of the biggest challenges with

  3. 0:08

    building a single page application is

  4. 0:10

    making the app visible to search engines

  5. 0:11

    and Link BOTS

  6. 0:12

    fortunately with angular Universal we

  7. 0:14

    have a reliable package for rendering

  8. 0:16

    our apps on the server not only does

  9. 0:18

    this provide SEO but it can also improve

  10. 0:20

    the initial page load speed in today's

  11. 0:22

    video you'll learn how to server-side

  12. 0:23

    render an angular app then deploy it to

  13. 0:25

    Google App Engine or firebase cloud

  14. 0:27

    functions if you're new here like and

  15. 0:29

    subscribe and make sure to follow along

  16. 0:31

    with the full source code on fire ship

  17. 0:32

    io let's start by talking about what

  18. 0:34

    server-side rendering is and when you

  19. 0:36

    would want to use it in any normal

  20. 0:38

    JavaScript app whether it be angular

  21. 0:39

    view or react you will provide the

  22. 0:41

    browser with a JavaScript bundle then

  23. 0:43

    the browser will parse that bundle of

  24. 0:44

    JavaScript and figure out how to render

  25. 0:46

    the HTML that's a great way to build a

  26. 0:48

    modern web app because it will make the

  27. 0:50

    user experience feel very fast and

  28. 0:51

    responsive like a native app but the

  29. 0:53

    problem is that a lot of bots out there

  30. 0:55

    don't execute JavaScript so that means

  31. 0:57

    if somebody shares a deep link in your

  32. 0:59

    app and that link renders some kind of

  33. 1:01

    dynamic content the only thing the bot

  34. 1:03

    will see is your initial index.html file

  35. 1:05

    so the purpose of angular Universal and

  36. 1:07

    server-side rendering is to offload some

  37. 1:09

    of this work to the server so when the

  38. 1:12

    user first visits a deep link they'll

  39. 1:13

    get some rendered HTML with the dynamic

  40. 1:15

    content already included for example the

  41. 1:18

    Twitter bot just wants to read the meta

  42. 1:19

    tags and ahead of the document so it's

  43. 1:21

    just going to grab that HTML and then

  44. 1:23

    not worry about executing any JavaScript

  45. 1:25

    on the page when you have just a regular

  46. 1:27

    user they'll get that same pre-rendered

  47. 1:28

    HTML so this usually results in a faster

  48. 1:30

    initial page load then angular's

  49. 1:32

    JavaScript will take over so it'll

  50. 1:34

    behave just like a regular angular app

  51. 1:36

    on subsequent navigations in order to

  52. 1:38

    make this possible we can't really use

  53. 1:40

    firebase hosting directly because it's

  54. 1:42

    just a static host we need an actual

  55. 1:44

    node.js server to dynamically render the

  56. 1:46

    content when a page is requested we have

  57. 1:48

    two good deployment options for a

  58. 1:50

    firebase project Google App Engine and

  59. 1:52

    firebase cloud functions there are some

  60. 1:54

    trade-offs between the two but I'll show

  61. 1:55

    you how to set up both of them in this

  62. 1:56

    video and they can both be used on the

  63. 1:58

    free tier I'm starting out from a brand