[{"id":"fullstackint-001","courseId":"fullstack-intermediate","domain":"frontend","topic":"Caching HTML and hashed assets","prompt":"Your SPA ships index.html plus bundles with content hashes in their names, like app.3f9a1c.js. After each deploy some users keep running old code for hours. Which Cache-Control setup fixes this without giving up caching?","hint":"One file name never changes, the others change on every build.","source":"https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control#caching_static_assets_with_cache_busting","interaction":{"type":"single"},"options":[{"id":"a","text":"index.html: no-store; bundles: no-cache, so every file is checked on each load","whyNot":"Revalidating hashed bundles on every load wastes requests, since a hashed file's content can never change under that name."},{"id":"b","text":"index.html: max-age=31536000, immutable; bundles: no-cache","whyNot":"This is backwards: the HTML that points at the new bundles would stay cached for a year."},{"id":"c","text":"index.html: no-cache; bundles: max-age=31536000, immutable","why":"The HTML is revalidated on each use so it picks up new bundle names, while hashed bundles are cached for good because a new build means a new URL."},{"id":"d","text":"Every file: max-age=3600, so all of them refresh within the hour","whyNot":"Users can still run a stale HTML page for up to an hour, and hashed bundles get refetched for no reason."}],"answer":"c","explanation":"Cache busting: put a hash in asset URLs and cache them forever, and make the entry HTML revalidate so it always points at the current assets.","concept":"Cache busting: put a hash in asset URLs and cache them forever, and make the entry HTML revalidate so it always points at the current assets.","rev":1,"kind":"scenario","takeaways":["Hashed assets: long max-age plus immutable. Entry HTML: no-cache, which means revalidate, not do not store."]},{"id":"fullstackint-002","courseId":"fullstack-intermediate","domain":"frontend","topic":"CORS preflight","prompt":"app.example.com calls api.example.com with a POST that sends JSON and an Authorization header. The console shows a CORS error, and the network tab shows an OPTIONS request that got 405 because the route only handles POST. What is the right fix?","hint":"The browser asks permission before it sends this request at all.","source":"https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS#preflighted_requests","interaction":{"type":"single"},"options":[{"id":"a","text":"Answer OPTIONS on the API with Access-Control-Allow-Origin, Allow-Methods including POST, and Allow-Headers listing Authorization and Content-Type","why":"The JSON content type and the Authorization header make this a preflighted request, so the server must approve the method and headers in its OPTIONS response first."},{"id":"b","text":"Set mode: \"no-cors\" on the fetch call so the browser skips the CORS checks","whyNot":"no-cors only allows simple requests and gives back an opaque response the script cannot read, so the API call is useless."},{"id":"c","text":"Add Access-Control-Allow-Origin to the POST response only, since that is the request that matters","whyNot":"The browser never sends the POST if the preflight fails, so headers on the POST response come too late."},{"id":"d","text":"Send the body as text/plain instead of JSON so the request becomes simple","whyNot":"The Authorization header alone still triggers a preflight, so the OPTIONS request keeps failing."}],"answer":"a","explanation":"Requests with non-safelisted headers or content types are preflighted with OPTIONS, and the server must answer it with the allowed origin, methods and headers.","concept":"Requests with non-safelisted headers or content types are preflighted with OPTIONS, and the server must answer it with the allowed origin, methods and headers.","rev":1,"kind":"scenario","code":"const api = \"https://api.example.com\";\nawait fetch(`${api}/orders`, {\n  method: \"POST\",\n  headers: {\n    \"Content-Type\": \"application/json\",\n    Authorization: `Bearer ${token}`,\n  },\n  body: JSON.stringify(order),\n});","takeaways":["A CORS error on OPTIONS means the server must handle the preflight, not that the client should hide headers."]},{"id":"fullstackint-003","courseId":"fullstack-intermediate","domain":"frontend","topic":"Reserving space for images (CLS)","prompt":"A blog's article images have no width or height attributes and are sized with CSS width: 100%. As each image loads, the text below jumps down, and the page's CLS score is poor. What is the most direct fix?","hint":"The browser can only hold space for a box whose proportions it knows before the file arrives.","source":"https://web.dev/articles/optimize-cls","interaction":{"type":"single"},"options":[{"id":"a","text":"Add loading=\"lazy\" to every image so they load after the text has settled","whyNot":"Lazy loading changes when images load, not whether space is held for them, so the text still jumps when they arrive."},{"id":"b","text":"Preload every image in the head so they arrive before the text renders","whyNot":"Preloading only changes download priority; the layout still has no size for the image until it decodes."},{"id":"c","text":"Set a fixed pixel height on every image in CSS so the box can never change","whyNot":"A fixed height distorts images at other widths; web.dev advises against a fixed height and recommends height: auto."},{"id":"d","text":"Add the real width and height attributes, and keep height: auto in CSS so the image stays responsive","why":"Browsers derive an aspect ratio from the width and height attributes before the image loads, so the space is reserved and nothing below it moves."}],"answer":"d","explanation":"Layout shift from images happens when the browser cannot reserve space before they load; width and height attributes give it the aspect ratio up front.","concept":"Layout shift from images happens when the browser cannot reserve space before they load; width and height attributes give it the aspect ratio up front.","rev":1,"kind":"scenario","takeaways":["Every img gets width and height attributes; CSS height: auto keeps it responsive."]},{"id":"fullstackint-004","courseId":"fullstack-intermediate","domain":"frontend","topic":"Cookies in a cross-site iframe","prompt":"Your support widget runs in an iframe on customers' sites and needs its own session cookie on every request it makes to your domain. Today the cookie is missing on those cross-site requests. Which TWO attributes must the cookie have?","hint":"One attribute allows the cross-site case, and that choice brings a second requirement.","source":"https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie#none","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"SameSite=None","why":"None is the value that sends the cookie on cross-site requests as well as same-site ones."},{"id":"b","text":"HttpOnly","whyNot":"HttpOnly only hides the cookie from JavaScript; it is good practice but does not decide whether the cookie is sent cross-site."},{"id":"c","text":"Secure","why":"A cookie with SameSite=None must also be Secure, so it is only set and sent over HTTPS."},{"id":"d","text":"SameSite=Lax","whyNot":"Lax withholds the cookie on cross-site subrequests such as the widget's calls from an iframe."}],"answer":"ac","explanation":"Cross-site cookies need SameSite=None, and SameSite=None requires the Secure attribute.","concept":"Cross-site cookies need SameSite=None, and SameSite=None requires the Secure attribute.","rev":1,"kind":"scenario","takeaways":["SameSite=None without Secure is rejected; always pair them."]},{"id":"fullstackint-005","courseId":"fullstack-intermediate","domain":"frontend","topic":"Microtasks and tasks","prompt":"An interviewer shows you this snippet and asks what it logs, in order.","hint":"Promise callbacks and timer callbacks wait in different queues.","source":"https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide","interaction":{"type":"single"},"options":[{"id":"a","text":"A, B, C, D","whyNot":"Neither callback runs while the current script is still executing, so D must come before B and C."},{"id":"b","text":"A, D, C, B","why":"The synchronous logs run first; then the microtask queue (the promise callback) is drained before the next task (the timeout) runs."},{"id":"c","text":"A, D, B, C","whyNot":"A zero-delay timeout is still a task, and all microtasks run before the event loop takes the next task."},{"id":"d","text":"A, C, D, B","whyNot":"then callbacks are always asynchronous, even on an already resolved promise, so D logs before C."}],"answer":"b","explanation":"After each task, the event loop runs every queued microtask (such as promise callbacks) before it starts the next task (such as a setTimeout callback).","concept":"After each task, the event loop runs every queued microtask (such as promise callbacks) before it starts the next task (such as a setTimeout callback).","rev":1,"kind":"scenario","code":"console.log(\"A\");\nsetTimeout(() => console.log(\"B\"), 0);\nPromise.resolve().then(() => {\n  console.log(\"C\");\n});\nconsole.log(\"D\");","takeaways":["Sync code, then all microtasks, then the next task: setTimeout 0 is never before a resolved promise's then."]}]