[{"id":"fullstackadv-001","courseId":"fullstack-advanced","domain":"frontend","topic":"Microtask starvation","prompt":"To keep the page responsive, a developer splits a heavy loop into a million promise callbacks. The spinner still never appears until all the work is done. Why?","hint":"Think about when the event loop lets the browser paint, and what has to be empty first.","source":"https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide","interaction":{"type":"single"},"options":[{"id":"a","text":"Promise callbacks run on a worker thread and only post their result back once the chain ends","whyNot":"Promise reactions run on the main thread as microtasks, not on a worker."},{"id":"b","text":"Microtasks queued by microtasks all run before the browser may render, so the queue never yields","why":"The event loop drains the microtask queue until it is empty, even as new microtasks are added, and only then may it update rendering. A self-feeding chain starves painting and input."},{"id":"c","text":"Promise.resolve() settles synchronously, so the whole chain runs inside the click handler itself","whyNot":"The then callbacks run after the handler returns, as microtasks; the problem is that they never stop before a render."},{"id":"d","text":"Browsers throttle promise callbacks to one per frame, so a million steps take far too long","whyNot":"There is no per-frame throttle on microtasks; they run back to back, which is exactly why nothing else gets a turn."}],"answer":"b","explanation":"The microtask queue is drained completely, including microtasks added while draining, before the next task or a render, so recursive microtasks block the page just like one long task.","concept":"The microtask queue is drained completely, including microtasks added while draining, before the next task or a render, so recursive microtasks block the page just like one long task.","rev":1,"kind":"scenario","code":"btn.onclick = () => {\n  spinner.hidden = false;\n  function step(i) {\n    if (i < 1e6) {\n      Promise.resolve().then(\n        () => step(i + 1));\n    }\n  }\n  step(0);\n};","takeaways":["Chunking work into promises does not yield to the browser; yield to a new task instead."]},{"id":"fullstackadv-002","courseId":"fullstack-advanced","domain":"frontend","topic":"content-visibility: auto","prompt":"A docs page renders 300 long sections, so the first render is slow. A teammate adds the CSS below, and rendering gets faster, but now the scrollbar jumps as users scroll. What explains it, and what fixes it?","hint":"Think about what height a section has while the browser is skipping its contents.","source":"https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/content-visibility","interaction":{"type":"single"},"options":[{"id":"a","text":"Skipped sections have no rendered contents to size them; contain-intrinsic-size gives a placeholder size, and auto keeps the last rendered size","why":"Off-screen sections are not laid out from their contents, so heights change as they render; contain-intrinsic-size: auto 500px supplies an estimate and then remembers the real size."},{"id":"b","text":"content-visibility: auto removes sections from find-in-page and tab order; switch to hidden to keep them","whyNot":"It is the other way round: auto keeps skipped contents available to find-in-page and focus, while hidden does not."},{"id":"c","text":"Each section is promoted to its own compositor layer; add will-change: transform so scrolling stays on the GPU","whyNot":"content-visibility turns on layout, style and paint containment; layer promotion has nothing to do with the jumping scrollbar."},{"id":"d","text":"Off-screen sections should get display: none from a scroll listener, which keeps their height while hidden","whyNot":"display: none gives an element no box at all, so heights would still change, and a scroll listener adds main-thread work."}],"answer":"a","explanation":"content-visibility: auto lets the browser skip rendering off-screen content; pair it with contain-intrinsic-size so skipped sections keep a stable size.","concept":"content-visibility: auto lets the browser skip rendering off-screen content; pair it with contain-intrinsic-size so skipped sections keep a stable size.","rev":1,"kind":"scenario","code":"section {\n  content-visibility: auto;\n}","takeaways":["content-visibility: auto needs contain-intrinsic-size to avoid scroll jumps."]},{"id":"fullstackadv-003","courseId":"fullstack-advanced","domain":"frontend","topic":"Vary and content negotiation","prompt":"/products/42 returns HTML or JSON depending on the Accept header, and sits behind a CDN with public caching. Some visitors now see raw JSON in their browser. What is the right fix?","hint":"The cache key has to include whatever request header chose the representation.","source":"https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Vary","interaction":{"type":"single"},"options":[{"id":"a","text":"Send Vary: Accept on every response for that URL, including 304 responses","why":"Vary makes caches store a separate response per value of the listed headers, and it should be the same on all responses for the URL, 304s included."},{"id":"b","text":"Send Cache-Control: private so the CDN keeps a separate copy for each visitor","whyNot":"private forbids shared caches from storing the response at all, so it removes the CDN's benefit instead of keying it."},{"id":"c","text":"Send Vary: * so the CDN keys the response on all the request headers","whyNot":"Vary: * says factors beyond request headers shaped the response, which makes it effectively uncacheable."},{"id":"d","text":"Send Vary: Accept only on the HTML responses, since browsers ask for HTML","whyNot":"If the JSON response lacks Vary, a cache can store it unkeyed and serve it to browsers; every representation needs the same Vary."}],"answer":"a","explanation":"When a response depends on a request header, the Vary header adds that header to the cache key; it must be consistent across all responses for the URL.","concept":"When a response depends on a request header, the Vary header adds that header to the cache key; it must be consistent across all responses for the URL.","rev":1,"kind":"scenario","takeaways":["Content negotiation behind a shared cache needs Vary on every variant."]},{"id":"fullstackadv-004","courseId":"fullstack-advanced","domain":"frontend","topic":"Credentialed CORS","prompt":"A SPA on https://app.example.com calls https://api.example.com with fetch, credentials: 'include', method POST and a JSON body. Which TWO statements are true?","hint":"Check the content type against the simple-request rules, and what credentials forbid.","source":"https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"The browser sends an OPTIONS preflight first, because application/json is not a simple content type","why":"Only form-urlencoded, multipart/form-data and text/plain keep a POST simple; JSON triggers a preflight."},{"id":"b","text":"The API may reply Access-Control-Allow-Origin: * as long as it also sends Allow-Credentials: true","whyNot":"For credentialed requests the wildcard is not allowed; the browser blocks the response and reports a CORS error."},{"id":"c","text":"The preflight carries the session cookie, so the API can reject unauthenticated users before the POST","whyNot":"CORS preflight requests never include credentials, so authorization cannot happen on the OPTIONS request."},{"id":"d","text":"The API must echo the exact origin and send Access-Control-Allow-Credentials: true, or the page cannot read it","why":"Credentialed responses need an explicit origin and Allow-Credentials: true; otherwise the browser does not expose the response."}],"answer":"ad","explanation":"Non-simple requests are preflighted without credentials, and credentialed CORS responses must name the origin explicitly and opt in with Access-Control-Allow-Credentials.","concept":"Non-simple requests are preflighted without credentials, and credentialed CORS responses must name the origin explicitly and opt in with Access-Control-Allow-Credentials.","rev":1,"kind":"scenario","takeaways":["Credentials rule out every CORS wildcard; preflights never carry cookies."]},{"id":"fullstackadv-005","courseId":"fullstack-advanced","domain":"frontend","topic":"Cookie prefixes","prompt":"A security review asks you to lock the session cookie to the exact host so no subdomain can set or read it, over HTTPS only. Which Set-Cookie header does the browser accept and meet the goal?","hint":"One cookie name prefix comes with strict rules on Domain and Path.","source":"https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie","interaction":{"type":"single"},"options":[{"id":"a","text":"__Host-sid=abc; Secure; Path=/; Domain=example.com","whyNot":"A __Host- cookie must not have a Domain attribute, so the browser rejects this one."},{"id":"b","text":"sid=abc; HttpOnly; SameSite=None","whyNot":"SameSite=None requires Secure, and without a prefix nothing stops a subdomain from setting a cookie with the same name."},{"id":"c","text":"__Host-sid=abc; Secure; HttpOnly","whyNot":"A __Host- cookie must also set Path=/, so this header is rejected."},{"id":"d","text":"__Host-sid=abc; Secure; HttpOnly; Path=/","why":"The __Host- prefix demands Secure, an HTTPS origin, no Domain and Path=/, which binds the cookie to this host only."}],"answer":"d","explanation":"The __Host- prefix makes the browser enforce Secure, no Domain and Path=/, so the cookie is host-only and cannot be planted from a sibling subdomain.","concept":"The __Host- prefix makes the browser enforce Secure, no Domain and Path=/, so the cookie is host-only and cannot be planted from a sibling subdomain.","rev":1,"kind":"scenario","takeaways":["__Host- means Secure, Path=/ and no Domain, enforced by the browser."]}]