updates on offline: “my appcache won’t come back” and “serviceworker tricks for cache”

32
Updates on Offline “My AppCache won’t come back” and “ServiceWorker Tricks for Cache” Natasha Rooney Web Technologist GSM Association @thisNatasha

Upload: natasha-rooney

Post on 06-May-2015

1.533 views

Category:

Technology


3 download

DESCRIPTION

My slides from my talk "Updates on Offline: “My AppCache won’t come back” and “ServiceWorker Tricks for Cache”" from Over the Air 2013 held in September in Bletchley Park. We had a good run-through of offline APIs in web, the mysteries of App Cache, and updates on the current status of ServiceWorker.

TRANSCRIPT

Page 1: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

Updates on Offline“My AppCache won’t come back” and “ServiceWorker Tricks for Cache”

Natasha RooneyWeb TechnologistGSM Association@thisNatasha

Page 2: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

1 boring slide about me.Aw, do we have to?Yup! It’s relevant (sorta)

1

Page 3: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

1 boring slide about me.Aw, do we have to?Yup! It’s relevant (sorta)

1

http://www.w3.org/Mobile/IG/

Page 4: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

1 boring slide about me.Aw, do we have to?Yup! It’s relevant (sorta)

1

http://www.w3.org/Mobile/IG/

Offline

Web Apps

Page 5: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

Why do we care?

2

Page 6: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

totemo CONFUSING desu ne?

紛らわしいからですね!

3

Page 7: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

totemo CONFUSING desu ne?

紛らわしいからですね!

3

Web StorageKey-value mapping

IndexedDBKey-value mapping +

indexes

File AccessReading file content

New HTML5 APIs

Page 8: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

totemo CONFUSING desu ne?

紛らわしいからですね!

3

App CacheBRAND NEW cache

mechanism of wonder which will answer all your questions of life’s worries and fulfill your every day

with the realisation of your dreams of riches, love, intelligence, regular full

nights of sleep and a real life Jurassic Park, or...

New HTML5 APIs

Page 9: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

NOT.

4

Page 10: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

NOT.

4

Manifest File

Content vs. Shell...

Page 11: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

5

Page 12: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

5

shell

content

Page 13: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

6

Page 14: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

6

content shell

Page 15: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

NOT.

7

App Cache is a Douchebag Gotchas

1. Files always come from the App Cache, even if you are offline

2. The App only updates if the manifest file changes

3. The App Cache is an additional cache, not an alternative one

4. Never future-cache the manifest

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

Page 16: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

NOT.

7

App Cache is a Douchebag Gotchas

1. Non cached resources will not load in a cached page

2. No more conditional downloads, including responsive images

3. No idea how the fallback page works

4. Redirects to other domains are treated like failures

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

Page 17: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

Another solution?

8

Page 18: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

ServiceWorker!9

Source: https://github.com/slightlyoff/ServiceWorker/blob/master/explainer.md

➔ New API➔ Power to the dev!➔ Apps, not pages - multi caches

Some quick interesting bits:➔ Documents and Service Workers are BFFs➔ Default Fallback: Normal resource loading➔ Wildcards are OK➔ 2 Service Workers are OK (default is last one)➔ Inception is NOT OK

Register

Page 19: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

ServiceWorker: ctrl.js

10

Source: https://github.com/slightlyoff/ServiceWorker/blob/master/explainer.md

Page 20: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

ServiceWorker: Caching!

11

Source: https://github.com/slightlyoff/ServiceWorker/blob/master/explainer.md

Page 21: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

BREAK: Promises

① History➔ Multilisp➔ Java Futures

BREAK

Page 22: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

BREAK: Promises

① Current Complexity

BREAK

Source: http://www.html5rocks.com/en/tutorials/async/deferred/

Page 23: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

BREAK: Promises

① New Promises

BREAK

Source: http://www.html5rocks.com/en/tutorials/async/deferred/

Page 24: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

ServiceWorker: Caching!

11

Source: https://github.com/slightlyoff/ServiceWorker/blob/master/explainer.md

Page 25: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

ServiceWorker: Caching

12

Source: https://github.com/slightlyoff/ServiceWorker/blob/master/explainer.md

Page 26: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

ServiceWorker: Caching

Also use ➔ e.respondWith(this.caches.match("shell-v1", e.request.url));

12

Source: https://github.com/slightlyoff/ServiceWorker/blob/master/explainer.md

Page 27: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

Offline? Yeah!

13

Page 28: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

ServiceWorker: Fallbacks

14

Source: https://github.com/slightlyoff/ServiceWorker/blob/master/explainer.md

Page 29: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

ServiceWorker: RULES

15

Source: https://github.com/slightlyoff/ServiceWorker/blob/master/explainer.md

1. Documents and Service workers are BFFs2. ServiceWorkers should be written to avoid holding global

state3. New tab means same ServiceWorker4. Version your ServiceWorkers!5. ServiceWorkers cannot be served on CDNs6. CORS7. importScripts() that run before oninstall finishes will go in

browser cache8. Use Cache-Control: no-cache or Cache-Control: private

Page 30: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

The bits I REALLY like...

Some cool stuff about ServiceWorkers

➔ Fallbacks for fallbacks for fallbacks➔ It’s 100% or nothing➔ “User chooses” or “dev chooses” both OK!➔ Work with Quota API➔ Works with Installed Apps

What about Network Information APIs?

16

Page 31: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

What we learnt...Did we learn anything?!

- The W3C cares about mobile!

- Offline solutions are confusing

- App Cache was not fit for purpose

- Shell and Content

- Service WorkerOffline as a side effectPromisesBit of rule followingmulti cache, multi fallback

17

Page 32: Updates on Offline: “My AppCache won’t come back” and  “ServiceWorker Tricks for Cache”

Thanks!

18

Especially...

Alex Russell | Google@slighltylate

Jake Archibald | Google@jaffathecake

Jonas Sicking | Mozilla @SickingJ

Jeremy Chone | Britesnow@JeremyChone