ANGULAR UNIVERSAL
MICHAEL HABERMAN
INDEPENDENT CONSULTANT
ABOUT ME
• Fullstack independent consult
• AWS Solution Architect
• Microsoft certified trainer
• Google developer group organizer
• Enough about me, lets talk Angular
WEB HISTORY
• Directory browsing
Request page
Browser Backend
Static page
WEB HISTORY
• Dynamic pages
Query DB &
Request page Generate HTML
Browser Backend
Static page
WEB HISTORY
• Dynamic pages + Javascript
Query DB &
Request page Generate HTML
Browser Backend
Static page + javascript
Form validation
Animation
WEB HISTORY
• Client side rendering - SPA
Request page
Browser Backend
Bundled app
Rendering &
App state
PROBLEM WITH CLIENT SIDE RENDERING
• Increase load time
• Crawler / Bots:
• SEO (SEO speed test)
• Social sharing (Open graph debugger)
INCREASE LOAD TIME
HOW TO SOLVE IT?
• Combine server rendering with client rendering
WEB HISTORY
• Client side rendering - SPA
Request page
Browser Backend
Static page + Bundled app
1) Render static page
2) Bootstrap angular
RENDERING OPTIONS
• Pre-render:
• While building render HTML
• Fast (just serve, store in CDN)
• Static
• Re-render
• Render in runtime
• More flexible
• Lest performance
COMBINE SERVER AND CLIENT RENDERING
WHERE AM I ?!
• Detect platform:
• Show different UI
• Log different data
• Access different resource ( DB vs API )
CHECK PLATFORM
ROUTING
• Domain.com/about
• Need to render index.html + component
• Declare in angular
• Declare in express
ROUTING
CLIENT-SERVER SYNC
• Server render is complete, angular is booting
• User had input text to control
• Angular takes over….
• We lost state!!
PREBOOT
• Solve sync issue
• Re-fire DOM events
• Maintain focused element
• https://universal.angular.io/api/preboot/index.html
TRANSFER FROM SERVER TO CLIENT
• User gets static HTML
• Preboot creates hidden div & record events
• Angular bootstrapping + loading external resource
• Angular call notify preboot once completed
• Preboot re-fire event to angu;ar
• Preboot witch view & cleanup
LIMITATIONS
• Browser API & DOM (document.getElementById, jquery, localStorage)
• isPlatformServer()
• Don’t use nativeElement, user elementRef
• Consider API calls
• Angular 2 and above
MORE FRAMEWORKS
• Node.js ( express, hapi.js and more )
• .NET core
• More to come…
ANGULAR 1
• No out-of-the-box solution
• Node.js headless Chrome
SEED PROJECT
• https://github.com/AngularClass/angular-starter
QUESTIONS
• Thank you!
• [email protected]
• @hab_mic