Web Technology Basics

Which of the following correctly describes a Service Worker?

  1. AA program that keeps running on a web server and handles database queries in response to requests from browsers
  2. BA CSS feature for speeding up drawing by rewriting the page's DOM directly, which can also be used on pages that are not HTTPS
  3. CA script that runs inside the browser separately from the page, can intercept the page's requests and return stored responses, and is used for offline display
Show answer and explanation

Answer: C. A script that runs inside the browser separately from the page, can intercept the page's requests and return stored responses, and is used for offline display

A Service Worker is a script registered by a page that runs inside the browser separately from the page. It receives the requests made by pages of its origin (the fetch event) and can decide in script whether to send them to the network or to return a stored response. With it, pages can be shown even offline and push notifications can be received. Because it has the powerful ability to intercept communication, it can be used only on HTTPS pages (and on localhost for development), and it cannot touch the DOM directly.

  • A. Application servers and the like run on servers; a Service Worker runs inside the browser.
  • B. A Service Worker is a script written in JavaScript, and it cannot touch the DOM directly.
  • C. Correct. It intercepts the page's requests and is used for offline display with stored responses and similar purposes.
Practice this topic Back to topic

Books on Web Technology Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Web Technology Basics questions

  1. For a page with responsive design that also supports smartphones, which of the following is the main purpose of writing <meta name="viewport" content="width=device-width, initial-scale=1"> in <head>?
  2. The response for a "my page" whose content differs for each user is given Cache-Control: private, max-age=60. Which of the following correctly describes the effect of this setting?
  3. When a web server compresses responses with gzip or Brotli before sending them, which of the following generally gains the least reduction in transferred data from compression?
  4. 1.5 MB of text data is compressed with gzip to one third of its size and sent. The bandwidth is 10 Mbps and the RTT is 100 ms, and before the data starts to be sent, the TCP connection, the TLS handshake and the HTTP request take three round trips in total. Assume 1 MB = 10^6 bytes, and ignore compression and decompression time, headers and waiting caused by TCP congestion control. Which of the following is closest to the time until all the data has been received?
  5. A CDN receives 2,000 requests per second, and its cache hit ratio rises from 90% to 98%. The response time is 20 ms on a hit, and 200 ms on a miss because the content is fetched from the origin server and returned; only requests that miss reach the origin server. Which of the following is the combination of the number of requests reaching the origin server and the average response time after the ratio reaches 98%?