Web Performance & Optimization MCQs for the NSCT
Web performance optimisation means making pages load, respond and stay visually stable faster, mainly through caching, smaller files (minification and compression), lazy loading and measuring the result with Core Web Vitals. It is the 13th of the 17 topics in the Web Development area, which carries 10% of the NSCT according to HEC's Areas of Competencies.
Web was the strongest area in 2026 at 54.1% accuracy, per APP and the HEC NSCT report. Expect short calculations (hit ratios, payload sizes, download times) and "which fix targets the cause" questions. The HTTP headers involved come from Web Architecture & Protocols.
Caching
A cache keeps a copy of a response so later requests skip some or all of the network. Browsers, CDNs (content delivery networks, which serve copies from edge servers near the user) and service workers all cache. The Cache-Control header sets the rules:
| Directive | Meaning |
|---|---|
max-age=3600 |
Fresh for 1 hour; reused with no request |
no-cache |
May store, but must revalidate before each use |
no-store |
Must not store at all |
immutable |
Will never change; do not revalidate |
When a copy goes stale, the browser revalidates with If-None-Match (carrying the ETag) and gets 304 Not Modified with no body if nothing changed. Long-lived assets use content-hashed filenames such as app.3f9a2c.js, so a new release gets a new URL.
Hit ratio = hits / (hits + misses). With a 0.9 hit ratio, 20 ms hits and 200 ms misses, the average is 0.9 × 20 + 0.1 × 200 = 38 ms.
Exam angle: no-cache does not mean "do not cache". That is no-store.
Minification
Minification removes whitespace, comments and long local names at build time without changing behaviour. Compression (gzip or Brotli) then encodes repeated patterns during transfer, so the savings stack: a 400 KB file minified by 30% and then gzipped to 25% sends 400 × 0.7 × 0.25 = 70 KB.
Related build steps are bundling (combining modules), tree shaking (dropping unused ES module exports) and code splitting (loading chunks on demand with import()).
Exam angle: minification is not encryption and not compression; it is a source rewrite.
Lazy loading
Lazy loading postpones resources until they are needed. For images, <img loading="lazy"> waits until the image nears the viewport. For code, dynamic import() loads a module only when a route uses it. For scripts, defer downloads in parallel and runs in document order after parsing, while async runs each script as soon as it arrives, in no fixed order.
Exam angle: never lazy-load the hero image above the fold. It is usually the LCP element, and lazy loading delays it.
Core Web Vitals
Google's Core Web Vitals measure real-user experience. Since 12 March 2024, INP (Interaction to Next Paint) has replaced FID (First Input Delay).
| Metric | Measures | Good | Poor |
|---|---|---|---|
| LCP (Largest Contentful Paint) | Loading | ≤ 2.5 s | > 4 s |
| INP (Interaction to Next Paint) | Responsiveness | ≤ 200 ms | > 500 ms |
| CLS (Cumulative Layout Shift) | Visual stability | ≤ 0.1 | > 0.25 |
Values between the two columns "need improvement". A page passes when the 75th percentile of real page loads is good. Each layout shift scores impact fraction × distance fraction, and CLS is the largest burst (session window) of shifts. Lab tools such as Lighthouse simulate one load; field data such as CrUX (Chrome User Experience Report) comes from real users.
Exam angle: older notes still list FID with a 100 ms threshold. Current answers use INP and 200 ms.
Common traps
- Reading
no-cacheas "never cache". It means "revalidate first". - Thinking an ETag removes the request. A 304 still costs a round trip.
- Using
asyncfor scripts that depend on each other. Usedefer. - Adding
loading="lazy"to the LCP image. - Forgetting to convert bytes to bits: 2 MB over 8 Mbps takes 2 s, not 0.25 s.
- Quoting FID as a current Core Web Vital.
Worked examples
1. Understanding. Which header lets a browser store a response but forces it to check with the server before every reuse?
Answer: Cache-Control: no-cache. no-store forbids storage entirely.
2. Application. An edge cache answers 720 of 900 requests itself. What share of requests reaches the origin? Answer: misses = 900 − 720 = 180, and 180 / 900 = 20%. The hit ratio is 80%.
3. Analysis. A news page shows CLS 0.28 because web fonts load late and the text reflows, and images have no size attributes. What should you fix first?
Answer: give images width and height (or aspect-ratio) so the browser reserves space, and use a font-loading strategy with a size-matched fallback. Both remove the shifts; faster servers only move them earlier.
Practise
The quiz below has 100 questions on this topic, filterable by tier and difficulty.
Practise: 100 questions
FAQs
Is minification the same as compression?
No. Minification rewrites the source at build time by removing spaces, comments and long names. Compression such as gzip or Brotli encodes the bytes during transfer, and the browser decompresses them. You normally use both, because compression still finds repeated patterns in minified code.
Which Core Web Vitals should I learn for the exam?
Learn LCP, INP and CLS with their thresholds: 2.5 s, 200 ms and 0.1 for good, and 4 s, 500 ms and 0.25 for poor. INP replaced FID in March 2024, so treat FID as a historical metric. Also remember that the assessment uses the 75th percentile of real page loads.
When should I use a CDN?
Use one when users are spread far from your server or when static files make up most of your traffic. A CDN cuts round-trip time and offloads the origin. Its gain depends on the hit ratio, so cache headers and hashed filenames matter as much as the CDN itself.
What is the difference between preload and prefetch?
preload fetches a resource the current page needs soon, at high priority, such as the hero image or a key font. prefetch fetches something the next page will probably need, at low priority when the browser is idle. Misusing preload can compete with more important downloads.
Next step
Continue with Web Testing & Debugging, the next topic in HEC's order. You can also return to the Web Development MCQs hub or test yourself in an NSCT mock test.