Growth of mobile web traffic has been outpacing desktop web traffic for years, and data reveals that users are likely to abandon experiences that too long to load.
Progressive web apps aim to be reliable, fast and engaging, regardless of form factor or quality of internet connection. We'll walk through several key aspects of PWAs, illustrating performance and usability improvements by showing quantitative comparisons to an equivalent "classic SPA".
7. Benefits of Each
Approach
WebNative
• Presence on home screen
• Background functionality
• Fast return startup
• Doesn’t require install
• Cross-Platform
• Very similar to desktop web experience
15. Server-Side Rendering
• ⏱ Don’t have to wait for client-side JS
• 🔗 Better for SEO & sharing links
• ⚠ Node.js and the Browser are different
• 👷 Try not to do the same work twice
• ⚡ HTML is assembled in your data center
17. Resource Caching Strategies
• Content at a URL is never
changed
• max-age=year
• index.html is the key
• Offline-friendly
• Content at a URL can change
• Cache-Control: no-cache
• Use Last-Modified or ETag
• Involves extra network
requests
Immutable Content “Check w/ server”
18. Service Workers
• A programmable network proxy
• A JavaScript worker
• Only works over HTTPS
• Has a predictable lifecycle
XHR SW WWW
Cache
20. Service Workers
I need item.pngApp
Of course! Here it is.
I have a list of important
resources. I’ll fetch them
all and cache them.
Cache
Precache
🖼
22. Service Workers
Took too long. Here’s a
cached version🖼
App
Ok, I’ll get it
Cache
Network or Cache
I need item.png
23. Service Workers
App
Ok, I’ll get it
Cache
Network or Cache
I need item.png
Something went wrong.
Here’s a cached version🖼
24. Service Workers
App
I’ll go download a new
copy in case it changed
Here’s a cached version
Cache
Cache and Update
🖼
I need item.png
Next time you ask, you’ll
get this new version
25. Service Workers
App
I’ll go download a new
copy in case it changed
Here’s a cached version
Cache
Cache, Update and Refresh
🖼
I need item.png
Hey! I’ve got a new
version. Ask me for itpostMessage
🎆
29. Storing Dynamic Content
• Cookies - Not worker-friendly, just a string
• LocalStorage - See 👆
• What’s left???
30. Storing Dynamic Content
• Cookies - Not worker-friendly, just a string
• LocalStorage - See 👆
IndexedDB
31. IndexedDB
• 🔢 Versioned
• 🗃 Indexable
• ⚙ Worker-Friendly
• 📅 Durable
• 🔣 Supports values of many types
• ⚠ Not a SQL, or a relational DB
32. IndexedDB
!// Open (or create) the database
let open =
indexedDB.open('MyDatabase', 1);
!// Create and/or Migrate the Schema
open.onupgradeneeded = (evt) !=> {
!// Transactions
open.onsuccess = () !=> {
!!... };
!!... };
33. IndexedDB
!// Create and/or Migrate the Schema
open.onupgradeneeded = (evt) !=> {
};
let db = open.result;
let store = null;
switch (evt.oldVersion) {
case 0: !// Upgrade from 0
!// !!...
case 1: !// Upgrade from 1
!// !!...
}
34. IndexedDB
!// Open (or create) the database
let open =
indexedDB.open('MyDatabase', 1);
!// Create and/or Migrate the Schema
open.onupgradeneeded = (evt) !=> {
!// Transactions
open.onsuccess = () !=> {
!!... };
!!... };