serviceworker: new game changer is coming!

22
Service Worker New game changer is coming :)

Upload: chang-w-doh

Post on 08-Sep-2014

1.673 views

Category:

Technology


4 download

DESCRIPTION

I believe ServiceWorker is one of most important specifications for the next web world. Offline and its technologies are very friendly concepts to native application developers. But, now I think front-end developers have to know that for stepping into new paradigm. With ServiceWorker, you can make your web application can run offline, and it also means you can make your web application load extremely fast. I've told about ServiceWorker very briefly in this slide. But you can understand how ServiceWorker runs on. If you want to know its usage, I highly recommend Topeka, which is a polymer demo application at google I/O 2014, that also includes material design and ServiceWorker in inside of it. If you want to know ServiceWorker some more or in detail, I'd like to recommend to read the following, written by Jungkee Song, one of authors of this spec. http://www.slideshare.net/jungkees/service-workers

TRANSCRIPT

Page 1: ServiceWorker: New game changer is coming!

Service WorkerNew game changer is coming :)

Page 3: ServiceWorker: New game changer is coming!

App. Cache!!App. Cache!!Offline!!

Offline!!

Image: ‘Mission Impossible 4’ Movie

Page 4: ServiceWorker: New game changer is coming!

We forgot something!But…what?

Page 5: ServiceWorker: New game changer is coming!

● Truely controlling offline resources○ Application Cache? OMG!○ Everything managed by your webbrowser!

● Plus, background processing○ Remote Push Notification, Alarm,

Background-update of resources, ...○ Everything run on your webpage!

Mission Impossible:before the ‘ServiceWorker’!

Page 6: ServiceWorker: New game changer is coming!

● Truely controlling offline/network stack○ Programmable cache control○ Custom response

● Plus, background processing○ Remote Push Notification○ Task Scheduler(e.g. Local Notification)○ BackgroundSync○ ...

Mission completed:‘ServiceWorker’ solves...

Page 7: ServiceWorker: New game changer is coming!

Yay,ServiceWorker!!

Page 8: ServiceWorker: New game changer is coming!

● Specification is worked in progress. But,○ Installed

■ https://slightlyoff.github.io/ServiceWorker/spec/service_worker/

○ Activating■ http://www.w3.org/TR/service-workers/

● See also: Is Service Worker ready?○ https://jakearchibald.github.

io/isserviceworkerready/

Is Service Worker available?

http://www.slideshare.net/jungkees/service-workersa

Page 9: ServiceWorker: New game changer is coming!

● Event-driven scripts○ that run independently of web pages

● ServiceWorker has○ Access to domain-wide events such as

network fetches○ scriptable caches○ The ability to respond to network requests

from certain web pages via script■ A way for applications to "go offline"

Overview:Service Worker

http://www.slideshare.net/jungkees/service-workersa

Page 10: ServiceWorker: New game changer is coming!

● Principles & terms○ Run on same origin○ Registration keyed by URL scope○ Document is controlled by matching

SeviceWorker upon navigation○ Successfully installed worker is considered

worker in waiting○ Lifecycle events○ Functional events

Overview:Service Worker

http://www.slideshare.net/jungkees/service-workersa

Page 11: ServiceWorker: New game changer is coming!

● Security○ Origin relativity○ Cross origin resource○ HTTPS only: preventing man-in-the-middle

attacks

Overview:Service Worker

http://www.slideshare.net/jungkees/service-workersa

Page 12: ServiceWorker: New game changer is coming!

Typical network fetch:Sufficient response

http://www.slideshare.net/jungkees/service-workersa

Page 13: ServiceWorker: New game changer is coming!

Typical network fetch:Insufficient response

http://www.slideshare.net/jungkees/service-workersa

Page 14: ServiceWorker: New game changer is coming!

With ServiceWorker:Bring your own cache

http://www.slideshare.net/jungkees/service-workersa

Page 15: ServiceWorker: New game changer is coming!

With ServiceWorker:Fallback to network

http://www.slideshare.net/jungkees/service-workersa

Page 16: ServiceWorker: New game changer is coming!

What can we do with ServiceWokers?

● Eliminating loading time○ Developer knows what is most important

resource in our webpages.■ We can control ‘request/response flow’ and

‘cache’ with ServiceWorker.

■ and Front-end developers just write their code without other libraries to control cache-flow.

○ Your page will be loaded in an instant!!!

● Other features come and see us soon. :)

Page 17: ServiceWorker: New game changer is coming!

● Type in the url box

● Check ‘enable’ like:

How to:enable ‘Service Worker’

chrome://flagsor

chrome://flags/#enable-service-worker

36+

Page 18: ServiceWorker: New game changer is coming!

● Type in the url box:

● To see the registrations:

How to:know ‘Service Worker is working’

chrome://inspect/#service-workers

chrome://serviceworker-internals

Page 19: ServiceWorker: New game changer is coming!

Demo from Google I/O 2014:Topeka

Page 20: ServiceWorker: New game changer is coming!

● Install

Demo from Google I/O 2014:Topeka

// ServiceWorker is ‘Installed’!!!this.addEventListener("install", function(e) { e.waitUntil( caches.create("core") // Creating Cache ‘core’! .then(function(core) { var resourceUrls = [ "", "?offline", "components/core-ajax/core-ajax.html", // ... ];

return Promise.all(resourceUrls.map(function(relativeUrl) { // Add resource to cache ‘core’ return core.add(baseUrl + relativeUrl); })); }));});

Page 21: ServiceWorker: New game changer is coming!

● fetchthis.addEventListener("fetch", function(e) { var request = e.request; if (this.scope.indexOf(request.origin) == -1) { return; }

// Basic read-through caching. e.respondWith( caches.match(request, "core").then( function(response) { return response; }, function() { // we didn't have it in the cache, so add it to the cache and return it return caches.get("core").then( function(core) { log("runtime caching:", request.url);

// FIXME(slighltyoff): add should take/return an array return core.add(request).then( function(response) { return response; });

// ...

Demo from Google I/O 2014:Topeka