โ† All HTML5 Flashcard Decks

HTML5 Web Workers Flashcards

7 cards from real HTML5 practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 7 HTML5 Web Workers flashcards as text
  1. Which of the following correctly checks if Web Workers are supported in the current browser?

    Answer: if (typeof Worker !== 'undefined') { ... }

    Checking typeof Worker !== 'undefined' is the standard feature-detection pattern for Web Workers before instantiating one.

  2. What happens to a Dedicated Web Worker when the web page that created it is closed?

    Answer: The worker is automatically terminated by the browser

    Dedicated Workers are tied to their creating browsing context and are terminated automatically when that page is closed or navigated away.

  3. In a Service Worker, what lifecycle event fires after installation, when the worker takes control of clients?

    Answer: activate

    The 'activate' event fires after a Service Worker is installed and ready to take control, making it the right place to clean up old caches.

  4. Which API do Service Workers use to cache network responses for offline use?

    Answer: Cache API (caches.open())

    The Cache API provides a storage mechanism specifically designed for Request/Response pairs, enabling Service Workers to serve cached content offline.

  5. What is the scope of a Service Worker, and how is it determined?

    Answer: The scope is the directory path of the service worker script file, controllable via the 'scope' option in registration

    By default, a Service Worker's scope is the directory it resides in, but it can be narrowed (not widened) using the scope option in navigator.serviceWorker.register().

  6. Which postMessage() syntax correctly transfers (not copies) an ArrayBuffer to a Web Worker?

    Answer: worker.postMessage(buffer, [buffer])

    The second argument to postMessage() is an array of Transferable objects; listing the buffer there marks it for zero-copy transfer instead of structured cloning.

  7. What is the correct way to register a Service Worker in a web application?

    Answer: navigator.serviceWorker.register('/sw.js')

    navigator.serviceWorker.register() is the standard API to register a Service Worker; it returns a Promise that resolves to a ServiceWorkerRegistration.