Sample questions
Question 1Easy
Which file describes a PWA's name, icons and display mode for installation?
- The web app manifest
- The service worker
- package.json "pwa" field
- robots.txt
Answer: A. The web app manifest
Explanation
The manifest (manifest.json / .webmanifest) gives install metadata such as name, icons, start_url and display.
Step-by-step solution
- The web app manifest describes how a PWA looks when installed.
- It holds name, icons, start_url and display mode.
- It is a JSON file linked from the page.
- So the correct answer is the web app manifest.
Why the other options are wrong
- B. The service worker handles requests, not install metadata.
- C. package.json has no pwa field used for installation.
- D. robots.txt controls crawlers, not app installation.
Tip: Manifest = install details (name, icons, display); service worker = offline and network logic.
Question 2Easy
Can a service worker access the DOM directly?
- Only after calling
self.attachDOM() - Yes; it can read and change
document directly - No; it communicates with pages through messages
- Only the DOM of the first page that registered it
Answer: C. No; it communicates with pages through messages
Explanation
Service workers run in a separate worker context without DOM access; they use postMessage and clients APIs.
Step-by-step solution
- Service workers run in a separate worker thread.
- Workers have no access to document or window.
- They talk to pages with postMessage and clients.
Why the other options are wrong
- A. There is no attachDOM method.
- B. No DOM access exists in workers.
- D. No page's DOM is accessible.
Tip: Worker = no DOM, use postMessage.
Question 3Easy
What is a service worker?
- A Web Worker that runs CSS animations off the main thread
- A server process that renders pages before sending them to the browser
- A browser extension that blocks unwanted network requests
- A background script that can intercept network requests
Answer: D. A background script that can intercept network requests
Explanation
Service workers sit between the page and the network, enabling offline support, caching strategies and push notifications.
Step-by-step solution
- A service worker is a script that runs in the background.
- It sits between the page and the network.
- It can intercept requests through the fetch event.
- So the correct answer is a background script that can intercept network requests.
Why the other options are wrong
- A. A service worker is not about CSS animations; it is for network interception.
- B. A service worker runs in the browser, not as a server process.
- C. A service worker is not a browser extension.
Tip: Service worker = programmable proxy in the browser for offline and caching.
Question 4Easy
Which event does a service worker listen to in order to intercept requests?
- request
- intercept
- load
- fetch
Answer: D. fetch
Explanation
The fetch event fires for requests within its scope; event.respondWith() supplies the response.
Step-by-step solution
- A service worker listens for events on the global scope.
- The fetch event fires for each request within its scope.
- event.respondWith() then provides the response.
- So the correct answer is the fetch event.
Why the other options are wrong
- A. Request is not a service worker event name.
- B. Intercept is not an event name; the event is fetch.
- C. Load is a page event, not the interception event.
Tip: In a service worker, use the fetch event and call event.respondWith().
Question 5Medium
A new service worker has installed but the old one still controls open tabs. What is its state by default?
- Active immediately in all open tabs
- Discarded because only one worker is allowed
- Redundant and must be registered again
- Waiting until the old worker's clients close
Answer: D. Waiting until the old worker's clients close
Explanation
By default the new worker waits so one version controls a page at a time; skipWaiting() can activate it sooner.
Step-by-step solution
- A new service worker installs and then waits.
- While an old worker still controls open pages, the new one does not take over.
- This keeps one version controlling a page at a time.
- So the correct answer is that it waits until the old worker's clients close.
Why the other options are wrong
- A. It does not activate at once by default; skipWaiting() changes that.
- B. Several workers can exist; only one controls pages at a time.
- C. The new worker is not redundant; it is waiting.
Tip: A new service worker waits by default; skipWaiting() and clients.claim() change that.
Question 6Medium
Which strategy suits frequently updated data where freshness matters but offline should still work?
- Cache-first with no expiry at all
- Network-first, falling back to the cache
- Cache-only, ignoring the network fully
- Network-only with no fallback
Answer: B. Network-first, falling back to the cache
Explanation
Network-first tries for fresh data and falls back to the last cached copy when offline.
Step-by-step solution
- The data changes often, so freshness matters.
- Network-first asks the network first for the latest data.
- If the network fails, the last cached copy is used, so offline still works.
- So the correct answer is network-first, falling back to the cache.
Why the other options are wrong
- A. Cache-first with no expiry serves stale data for a long time.
- C. Cache-only never gets fresh data.
- D. Network-only fails offline, which the question wants to avoid.
Tip: Fresh-but-offline-capable data: network-first with cache fallback.
Question 7Medium
What is the "activate" event typically used for?
- Deleting caches left by older versions
- Responding to network requests
- Showing the install prompt
- Pre-caching the files for the first time
Answer: A. Deleting caches left by older versions
Explanation
Activate runs when the new worker takes over, a safe point to remove outdated caches.
Step-by-step solution
- The activate event fires when a new worker takes over.
- The old version is no longer in use.
- It is the standard place to delete old caches.
Why the other options are wrong
- B. That is the fetch event.
- C. The install prompt is separate (beforeinstallprompt).
- D. Pre-caching belongs in the install event.
Tip: install = cache new, activate = clean old.
Question 8Medium
In a "cache-first" strategy, what happens on a request?
- Use the cached copy if present, else the network
- Never use the network once the cache is installed
- Return whichever of cache and network answers first
- Always go to the network and update the cache afterwards
Answer: A. Use the cached copy if present, else the network
Explanation
Cache-first is ideal for static assets: fast and offline-friendly, at the cost of possibly stale content.
Step-by-step solution
- Cache-first checks the cache before the network.
- If a cached copy exists, it is used.
- The network is only used when nothing is cached.
- So the correct answer is use the cached copy if present, else the network.
Why the other options are wrong
- B. Cache-first still uses the network when the cache has nothing.
- C. Racing both is a different strategy, not cache-first.
- D. Going to the network first is network-first or network-only.
Tip: Cache-first suits static assets; network-first suits fresh data.
Question 9Hard
What does the scope of a service worker registered at /app/sw.js default to?
- The whole origin from /
- /app/ and pages beneath it
- Only the page that registered it
- Only the file /app/sw.js itself
Answer: B. /app/ and pages beneath it
Explanation
The default scope is the directory of the script, so it controls /app/ and below.
Step-by-step solution
- Scope defaults to the directory containing the worker script.
- /app/sw.js gives scope /app/.
- Pages under /app/ are controlled.
Why the other options are wrong
- A. Widening scope needs the Service-Worker-Allowed header.
- C. It controls all pages in scope, not just one.
- D. Scope is a path prefix, not a single file.
Tip: Scope follows the script folder.
Question 10Hard
What is the "stale-while-revalidate" caching strategy in a service worker?
- Wait for the network and only use cached data when the request takes too long
- Respond only from the network and store nothing so that data is never stale
- Answer from cache now and refresh the cache from the network
- Delete the cache whenever a request fails, then wait for the next request
Answer: C. Answer from cache now and refresh the cache from the network
Explanation
It gives fast responses from cache while keeping it reasonably fresh for the next visit.
Step-by-step solution
- Stale-while-revalidate answers the request from the cache right away.
- At the same time it fetches from the network.
- The fresh response then updates the cache for the next visit.
- So the correct answer is answering from cache now and refreshing the cache from the network.
Why the other options are wrong
- A. This describes a network-first timeout, not stale-while-revalidate.
- B. Network-only stores nothing, which is not this strategy.
- D. Deleting the cache on failure is not a standard strategy.
Tip: Stale-while-revalidate: instant cached answer, refresh in the background.
Practise all 13 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →