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

angular pwa

angular pwa

Jecelyn Yeen

July 01, 2018
Tweet

More Decks by Jecelyn Yeen

Other Decks in Programming

Transcript

  1. @JecelynYeen From Kuala Lumpur, Malaysia • GDE - Web technologies,

    Angular • Software Architect @ Randstad Organizer:
  2. • PWA • Angular + PWA • How to start?

    • How does it works? • How to make it progressive?
  3. What is a Mobile App? • Searchable from App Store

    / Play Store • Installable & Remove-able (Show in Home Screen) • Workable / Semi-workable offline • Need to update • Talk to native api - camera / sensor / notification
  4. What is a Web? • Searchable from browser (an url

    away) • Have address bar • Cross platforms • Non-workable / Semi-workable offline • Refresh browser / Auto update • Talk to limited native api - camera / notification
  5. Web + App • Searchable from Play Store / Play

    Store web • Installable & Remove-able (Show in Home Screen) • No address bar • Cross platforms • Workable / Non-workable / Semi-workable offline • Refresh browser Need / Auto update • Talk to limited native api - camera / notification
  6. +

  7. How to Start? • npm install @angular/cli • ng new

    my-app-name Run in command line / terminal:
  8. How to Start? • ng add @angular/pwa + Run in

    command line / terminal: Build & Deploy it: • ng build --prod • deploy /dist/[project] folder to hosting
  9. Behind the scene, … • Creating manifest.json • Creating set

    of icons • Register service worker • Creating ngsw-config.json
  10. In Summary • Online: Load all assets from cache •

    Offline: Same as online https://www.pawtaro.com/ https://angular.io/guide/service-worker-getting-started
  11. NGSW configuration file { "assetGroups": [ Smart defaults for the

    app shell ], "dataGroups": [ Settings for your API, etc ], ... } ngsw-config.json
  12. NGSW configuration file { "index": "/index.html", "assetGroups": [{ "name": "app",

    "installMode": "prefetch", "resources": { "files": [ "/favicon.ico", "/index.html", "/*.css", "/*.js" ] } }] } ngsw-config.json / assetGroups • prefetch: fetch eagerly • lazy: fetch when we need
  13. NGSW configuration file { "name": "myApi", "urls": [ "/api/archive/**" ],

    "cacheConfig": { "strategy": "performance", "maxSize": 100, "maxAge": "365d" } } ngsw-config.json / dataGroups • performance: cache first • freshness: network-first
  14. SwUpdate Service constructor(updates: SwUpdate) { // force check for sw

    update updates.checkForUpdate(); // when sw update available updates.available.subscribe(event => { console.log('current version is', event.current); console.log('available version is', event.available); }); }
  15. Web + App • Searchable from Play Store / Play

    Store web • Installable & Remove-able (Show in Home Screen) • No address bar • Cross platforms • Workable / Non-workable / Semi-workable offline • Refresh browser Auto / Need update • Talk to limited native api - camera / notification
  16. Build the app using prod • Run ng build --prod

    • Using Ahead of Time compilation • Using Build Optimizer
  17. Use Lazy Loading • Download the only the code needed

    to start the app • Preload all the modules by using PreloadAllModules strategy • 100% flexibility with your custom PreloadingStrategy
  18. How to const appRoutes: Routes = [{ path: 'customers', loadChildren:

    'customers/customers.module#CustomersModule' }] app-routing.module.ts const customersRoutes: Routes = [ { path: '', component: CustomerListComponent }, { path: ':id', component: CustomerDetailsComponent } ]; customers / customers-routing.module.ts https://angular.io/guide/lazy-loading-ngmodules
  19. Consider Server Side Rendering (SSR) No SSR Load HTML SSR

    Load HTML Boostrap Boostrap First meaningful Paint <app-root> Loading</app-root> First meaningful Paint Loading • Better first load experience • Social links with preview of a website • Better for SEO
  20. How to • ng generate universal --client-project=ssr Long way •

    ng add @ng-toolkit/universal • npm run build:prod • npm run server Short way Follow the guide here: https://angular.io/guide/universal https://medium.com/@maciejtreder/angular-server-side-rendering-with-ng-toolkit- universal-c08479ca688