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

Polymer & PWA: Understanding the “why”

Polymer & PWA: Understanding the “why”

This talk was present during Google Developer Group Dev Fest 2017 at Bengaluru(Oct 7 2017) and Mumbai (28 Oct 2017).
The slide walks through the shortcomings of web platform and how web component solves them. Explains what is Polymer and how it can be used to build PWA.

Avatar for Ashrith Kulai

Ashrith Kulai

October 07, 2017

Other Decks in Programming

Transcript

  1. @ashrith_kulai #UseThePlatform HTML was meant for • Text content •

    Images • Interlinking with other HTML docs
  2. @ashrith_kulai #UseThePlatform Evolution of browsers • Serve dynamic content from

    server side • More capabilities - HTML spec evolution • ES5
  3. @ashrith_kulai #UseThePlatform Capable browsers led to • Complex processing at

    frontend - Web 2.0 • Patterns emerged into libraries/frameworks
  4. @ashrith_kulai #UseThePlatform Where are we Today? • Complex abstract frameworks

    • Framework clutter + fragmentation • Complex build tools to extract performance • Workarounds for how the platform is today
  5. @ashrith_kulai #UseThePlatform What we didn’t anticipate? • Mobile Web •

    Most of the frameworks are humongous for mobile • Mobile CPUs don’t have heatsinks like desktop!!!
  6. @ashrith_kulai #UseThePlatform Mutation of HTML • HTML moved away from

    original purpose and capabilities • HTML was not meant for Web Apps
  7. Web Component HTML Template • Enables you to define blocks

    of markup with the ability to inject dynamic content into
  8. Web Component Shadow DOM • Gives you the ability to

    scope markup and styles in a separate DOM tree
  9. Web Component HTML Import • Provides a way to include

    and reuse HTML documents in other HTML documents
  10. FRAMEWORKS (pseudo-parser) (pseudo-lifecycle) (handling DOM) Browser JS code How is

    it different? <tree-control> Browser native code Web Components (native parser) (native lifecycle) (handling DOM) <tree-control>
  11. FRAMEWORKS (pseudo-parser) (pseudo-lifecycle) (handling DOM) Browser native code Web Components

    (native parser) (native lifecycle) (handling DOM) Browser JS code Where Does Polymer fit in? POLYMER (not a new framework) (helper library)
  12. What is Polymer? Polymer is a JavaScript library that helps

    you create custom reusable HTML web components. @ashrith_kulai #UseThePlatform
  13. What’s in Polymer? • Syntactic sugar around WC • Data

    system • Event system @ashrith_kulai #UseThePlatform
  14. PWA with Polymer • Polymer-cli supports ◦ App shell architecture

    ◦ PRPL pattern ◦ Service worker ◦ HTTP/2 server push ◦ Unit testing ◦ Linter @ashrith_kulai #UseThePlatform
  15. Distribution of unbundled code with HTTP/2. One awesome thing that

    Polymer introduced @ashrith_kulai #UseThePlatform
  16. Parent Children Properties Events Store Data and Event flow between

    the components dispatch(...) getState(...)
  17. Parent Children Properties Events Store Data and Event flow between

    the components dispatch(...) getState(...) X
  18. Data flow within the components Observed property: active: { type:

    Boolean, observer: '_activeChanged' } _activeChanged(newValue, oldValue) { this.toggleClass('highlight', newValue); }
  19. Data flow within the components Observed property: active: { type:

    Boolean, observer: '_activeChanged' } _activeChanged(newValue, oldValue) { this.toggleClass('highlight', newValue); } Computed property: first: String, last: String, fullName: { type: String, computed: 'computeFullName(first, last)' }, computeFullName(first, last) { return first + ' ' + last; }
  20. Data flow within the components Observed property: active: { type:

    Boolean, observer: '_activeChanged' } _activeChanged(newValue, oldValue) { this.toggleClass('highlight', newValue); } Computed property: first: String, last: String, fullName: { type: String, computed: 'computeFullName(first, last)' }, computeFullName(first, last) { return first + ' ' + last; } One way Data binding: <div hidden$=[[active]]>
  21. Data flow within the components Observed property: active: { type:

    Boolean, observer: '_activeChanged' } _activeChanged(newValue, oldValue) { this.toggleClass('highlight', newValue); } Computed property: first: String, last: String, fullName: { type: String, computed: 'computeFullName(first, last)' }, computeFullName(first, last) { return first + ' ' + last; } One way Data binding: <div hidden$=[[active]]> Two way data binding: <input value="{{first::input}}" type="text"> <input value="{{last::input}}" type="text">
  22. @ashrith_kulai #olaforweb Polyspector Demo • Polyspector - A Chrome extension

    https://chrome.google.com/webstore/detail/polyspector/naoehbibkfilaolkmfiehggkfjndlhpd?utm_ source=chrome-ntp-icon
  23. @ashrith_kulai #UseThePlatform Building a PWA using Polymer Drawbacks • Needs

    polyfills for unsupported browsers (28KB) • IE support - 11+ • Flaky support on UC browser, older versions of Android browser & webviews • No server side rendering
  24. @ashrith_kulai #UseThePlatform Building a PWA using Polymer Advantages • Lightweight

    10KB and fast • Simple yet very powerful • Bye bye css preprocessors • Configurable build • Integrates well with any framework Drawbacks • Needs polyfills for unsupported browsers (28KB) • IE support - 11+ • Flaky support on UC browser, older versions of Android browser & webviews • No server side rendering
  25. @ashrith_kulai #UseThePlatform Overall conclusion • Exciting days ahead of us

    • Next billion Indian users • Better performance on mobile • The platform will offer better support for Web Apps