Service Workers API Flashcards

1
Q

What are service workers, as described by [Google Developers]?

A

A service worker is a script that is run by your browser in the background, separate from a web page, opening the door to features which don’t need a web page or user interaction. Today, they already include features like push notifications and background sync. [Google Developers]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are service workers, as described by [MDN]?

A

Service workers essentially act as proxy servers that sit between web applications, and the browser and network (when available). They are intended to (amongst other things) enable the creation of effective offline experiences, intercepting network requests and taking appropriate action based on whether the network is available and updated assets reside on the server. They will also allow access to push notifications and background sync APIs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the concept of a service worker [MDN]?

A

A service worker is an event-driven worker registered against an origin and a path. It takes the form of a JavaScript file that can control the web page/site it is associated with, intercepting and modifying navigation and resource requests, and caching resources in a very granular fashion to give you complete control over how your app behaves in certain situations (the most obvious one being when the network is not available.).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe the context of a service worker.

A

A service worker is run in a worker context: it therefore has no DOM access, and runs on a different thread to the main JavaScript that powers your app, so it is not blocking. It is designed to be fully async; as a consequence, APIs such as synchronous XHR and localStorage can’t be used inside a service worker.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe service worker security concerns.

A

Service workers only run over HTTPS, for security reasons. Having modified network requests wide open to man in the middle attacks would be really bad. In Firefox, Service Worker APIs are also hidden and cannot be used when the user is in private browsing mode.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Service workers make heavy use of these.

A

Promises.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe promises as used by service workers.

A

Service workers make heavy use of promises, as generally they will wait for responses to come through, after which they will respond with a success or failure action. The promises architecture is ideal for this.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How is a service worker first registered?

A

A service worker is first registered using the ServiceWorkerContainer.register() method.

If successful, your service worker will be downloaded to the client and attempt installation/activation (see below) for URLs accessed by the user inside the whole origin, or inside a subset specified by you.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the life cycle of a service worker?

A
  1. Download 2. Install 3. Activate
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How often is a service worker downloaded?

A

The service worker is immediately downloaded when a user first accesses a service worker–controlled site/page.

After that it is downloaded every 24 hours or so. It may be downloaded more frequently, but it must be downloaded every 24h to prevent bad scripts from being annoying for too long.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How many Interface methods does the service worker API have?

A

18.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly