Skip to content

Commit a2aa934

Browse files
committed
Some more slides related to service workers.
1 parent 2cff9e8 commit a2aa934

File tree

1 file changed

+74
-16
lines changed

1 file changed

+74
-16
lines changed

index.html

Lines changed: 74 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ <h3>Service Workers</h3>
300300
<ul class="no-bullets">
301301
<li>Give developers the moving parts to solve their problems</li>
302302
<li>Alow to create own caching patterns</li>
303+
<li>Can be only used over HTTPS (excluding localhost)</li>
304+
<li>Hijack connections</li>
305+
<li>Fabricate, and filter responses</li>
303306
</ul>
304307
</section>
305308

@@ -346,7 +349,9 @@ <h3>task.js (the worker)</h3>
346349
}, false);
347350
</code></pre>
348351

349-
<a href="https://www.html5rocks.com/en/tutorials/workers/basics/" class="credits" target="_blank">Code from https://www.html5rocks.com/en/tutorials/workers/basics/</a>
352+
<p>
353+
<a href="https://www.html5rocks.com/en/tutorials/workers/basics/" class="credits" target="_blank">Code from https://www.html5rocks.com/en/tutorials/workers/basics/</a>
354+
</p>
350355

351356
</section>
352357

@@ -374,13 +379,63 @@ <h3>Workers do NOT have access to:</h3>
374379
</ul>
375380
</section>
376381

382+
<section>
383+
<h1 style="font-size: 2em; margin-bottom: 0em;" class="fallbackColor" >Now</h1>
384+
<h1 style="font-size: 2.5em; margin-bottom: 0em;" class="primaryColor" >back to</h1>
385+
<h1 style="font-size: 3em;" class="secondaryColor" >service workers</h1>
386+
</section>
387+
388+
389+
<section>
390+
<h3>Service worker lifecycle</h3>
391+
<p style="font-size: 0.5em; margin-top:-1em">(on first installation)</p>
392+
<img class="plain" style="max-height: 11em;" src="/src/img/sw-lifecycle.png">
393+
<p>
394+
<a href="https://developers.google.com/web/fundamentals/getting-started/primers/service-workers" class="credits" target="_blank">Image from Google Web Fundamentals</a>
395+
</p>
396+
</section>
397+
398+
399+
<section>
400+
<h3>Register a service worker</h3>
401+
<pre><code class="javascript" data-trim data-noescape>
402+
if ('serviceWorker' in navigator) {
403+
navigator.serviceWorker.register('/sw.js')
404+
.then(function(registration) {
405+
// Registration was successful
406+
console.log('Registration successful with scope: ',
407+
registration.scope);
408+
}).catch(function(err) {
409+
// registration failed :(
410+
console.log('ServiceWorker registration failed: ', err);
411+
});
412+
}
413+
</code></pre>
414+
<p>
415+
<a href="https://developers.google.com/web/fundamentals/getting-started/primers/service-workers" class="credits" target="_blank">Code from Google Web Fundamentals</a>
416+
</p>
417+
</section>
418+
419+
420+
<section>
421+
<h3>Install a service worker</h3>
422+
<pre><code class="javascript" data-trim data-noescape>
423+
self.addEventListener('install', function(event) {
424+
// Perform install steps
425+
});
426+
</code></pre>
427+
<p>
428+
<a href="https://developers.google.com/web/fundamentals/getting-started/primers/service-workers" class="credits" target="_blank">Code from Google Web Fundamentals</a>
429+
</p>
430+
</section>
431+
377432
<section data-background-color="var(--secondary-color)">
378433
<h1 style="font-size: 2em; margin-bottom: 0em;" class="fallbackColor" >The</h1>
379434
<h1 style="font-size: 2.5em; margin-bottom: 0em;" class="primaryColor" >cache</h1>
380435
<h1 style="font-size: 3em;" class="flippedColor" >machine</h1>
381436
</section>
382437

383-
<!--https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/-->
438+
384439
<section>
385440
<h3>On install - as a dependency</h3>
386441
<img class="plain" style="max-height: 12em;" src="/src/img/cm-on-install-dep.png">
@@ -489,20 +544,23 @@ <h3>On user interaction</h3>
489544
<section>
490545
<h3>On user interaction</h3>
491546
<pre><code class="javascript" data-trim data-noescape>
492-
document.querySelector('.cache-article').addEventListener('click', function(event) {
493-
event.preventDefault();
494-
495-
var id = this.dataset.articleId;
496-
caches.open('mysite-article-' + id).then(function(cache) {
497-
fetch('/get-article-urls?id=' + id).then(function(response) {
498-
// /get-article-urls returns a JSON-encoded array of
499-
// resource URLs that a given article depends on
500-
return response.json();
501-
}).then(function(urls) {
502-
cache.addAll(urls);
547+
document.querySelector('.cache-article')
548+
.addEventListener('click', function(event) {
549+
event.preventDefault();
550+
551+
var id = this.dataset.articleId;
552+
caches.open('mysite-article-' + id)
553+
.then(function(cache) {
554+
fetch('/get-article-urls?id=' + id)
555+
.then(function(response) {
556+
// returns a JSON-encoded array of resource
557+
// URLs that a given article depends on
558+
return response.json();
559+
}).then(function(urls) {
560+
cache.addAll(urls);
561+
});
562+
});
503563
});
504-
});
505-
});
506564
</code></pre>
507565
<p>
508566
<a href="https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/" class="credits" target="_blank">Code from Jake Archibald`s offline cookbook</a>
@@ -535,7 +593,7 @@ <h1 style="font-size: 3.0em;" class="fallbackColor" >Can we use <a href="https:/
535593
</section>
536594

537595

538-
596+
539597

540598

541599
</div>

0 commit comments

Comments
 (0)