Offline First

An intro to Service Workers

A generic entry point for persistent event-driven background processing in the Web Platform.

– W3C Specification

 

  • Intercept Network Requests
  • Caching
  • ​Push Notifications  (Chrome Only, so far)
  • Background Sync  (One-day)
  • Geofencing  (One-day)

Features

  • Push Notifications  (Chrome Only, so far)
  • Background Sync  (One-day)
  • Geofencing  (One-day)

“Offline First”

What about AppCache?

Short answer: Deprecated

Long answer: AppCache is a Douchebag

http://alistapart.com/article/application-cache-is-a-douchebag

48.45%

(Partial Support…)

– caniuse.com

Promises

// Synchronous
try {
  var value = myFunction();
  console.log(value);
} catch(err) {
  console.error(err);
}

// Promise
myFunction()
  .then(function(value) {
    console.log(value);
  })
  .catch(function(err) {
    console.error(err);
  });

Fetch API

// jQuery AJAX
$.get('/some.json').done(function(data, status, xhr) {
  console.log(data);
});

// Fetch API
fetch('/some.json').then(function(response) {
  console.log(response);
})

Demo Time

Offline First

By Peter Browne

Offline First

An intro to Service Workers

  • 398