0 / 17 read
All topics

Performance & Security

Web performance optimization, caching, security, and accessibility

17 questions0 read8 interview prep

Questions9 shown

Key strategies:

1. Code Splitting — Load only the code needed for the current page

2. Lazy Loading — Defer images, components, and routes

3. Minification — Compress JS, CSS, and HTML

4. Compression — Enable Gzip/Brotli on the server

5. CDN — Serve assets from edge locations close to users

6. Image Optimization — Use WebP/AVIF, responsive srcset, lazy loading

7. Caching — Set proper Cache-Control headers

8. Tree Shaking — Remove unused code during bundling

9. Critical CSS — Inline above-the-fold CSS

10. Preload/Prefetch — Hint browser about critical resources

11. Font Display — Use font-display: swap to avoid FOIT

12. Reduce Third-Party Scripts — Defer or async non-critical scripts

A CDN (Content Delivery Network) is a network of geographically distributed servers that cache and deliver content from locations close to users.

Benefits:

1. Reduced latency — Content served from nearest edge server

2. Faster load times — Shorter physical distance = less travel time

3. Reduced server load — Origin server handles fewer requests

4. High availability — Redundancy across multiple locations

5. DDoS protection — Traffic distributed across network

6. Bandwidth savings — Cached content reduces origin bandwidth

7. SEO boost — Faster load times improve search rankings

Popular CDNs: Cloudflare, Vercel Edge Network, AWS CloudFront, Fastly, Akamai

**1. HTTP Cache (Browser Cache)** - `Cache-Control: max-age=3600` — Cache for 1 hour - `ETag` — Fingerprint for conditional requests - `Last-Modified` — Date-based validation **2. Service Worker Cach...

Sign in to continue reading

Create a free account to unlock login-level content, or go premium for everything.

**CORS (Cross-Origin Resource Sharing)** is a security mechanism that allows servers to specify which origins can access their resources. **Same-Origin Policy:** Browsers block requests to different ...

Sign in to continue reading

Create a free account to unlock login-level content, or go premium for everything.

**Core Web Vitals** measure real-world user experience: 1. **LCP (Largest Contentful Paint)** — Loading performance - Time for the largest element to render - Good: < 2.5s 2. **INP (Interactio...

Sign in to continue reading

Create a free account to unlock login-level content, or go premium for everything.

**`preload`** — Load critical resources for the current page with high priority: [code block] **`prefetch`** — Load resources for **future** navigation with low priority: [code block] **`preconnect`...

Sign in to continue reading

Create a free account to unlock login-level content, or go premium for everything.

Code-level optimizations:

1. Code splitting -- Load only what's needed for the current page

2. Tree shaking -- Remove unused code

3. Lazy loading -- Defer non-critical resources

4. Minification -- Reduce JS/CSS file sizes

5. Bundle analysis -- Identify and remove large dependencies

Asset optimization:

6. Image optimization -- WebP/AVIF, responsive images, lazy loading

7. Font optimization -- font-display: swap, subset fonts, preload critical fonts

8. Compress resources -- Gzip/Brotli compression

Network optimization:

9. CDN -- Serve assets from edge locations

10. HTTP/2 -- Multiplexing, server push

11. Caching -- Cache-Control headers, service workers

12. Preconnect/Preload -- Resource hints

Rendering:

13. SSR/SSG -- Server-rendered or pre-built HTML

14. Critical CSS -- Inline above-the-fold CSS

15. Defer non-critical JS -- async/defer attributes

A CDN (Content Delivery Network) is a geographically distributed network of servers that delivers web content to users from the nearest location.

How it works:

1. Origin server stores the original content

2. CDN copies content to edge servers worldwide

3. User requests are routed to the nearest edge server

4. Content is served from the edge (low latency)

Benefits:

1. Reduced latency -- Content served from nearby servers

2. Improved load times -- Faster delivery

3. Reduced bandwidth -- Origin server handles fewer requests

4. High availability -- If one server fails, others take over

5. DDoS protection -- Distributed infrastructure absorbs attacks

6. Caching -- Static assets cached at the edge

7. SSL/TLS -- Free HTTPS certificates

Popular CDNs: Vercel Edge Network, Cloudflare, AWS CloudFront, Akamai, Fastly

**1. HTTP Cache (Browser Cache):** - `Cache-Control: max-age=3600` -- Cache for 1 hour - `ETag` / `If-None-Match` -- Validation-based caching - `Last-Modified` / `If-Modified-Since` -- Date-based vali...

Sign in to continue reading

Create a free account to unlock login-level content, or go premium for everything.

Interview Preparation

Premium

High-signal questions that come up most in real interviews. These are the ones worth spending extra time on.

**XSS (Cross-Site Scripting)** injects malicious scripts into web pages. **Prevention strategies:** 1. **Input Sanitization** — Escape/sanitize all user input 2. **Output Encoding** — HTML-encode co...

Sign in to continue reading

Create a free account to unlock login-level content, or go premium for everything.

**CSRF (Cross-Site Request Forgery)** tricks users into making unwanted requests to a site where they are authenticated. **Prevention:** 1. **CSRF Tokens** — Include a unique, random token in every f...

Sign in to continue reading

Create a free account to unlock login-level content, or go premium for everything.

**SSG (Static Site Generation):** - Pages generated at **build time** - Served as static HTML files - Fastest performance - Best for content that rarely changes (blogs, docs) **SSR (Server-Side Rende...

Sign in to continue reading

Create a free account to unlock login-level content, or go premium for everything.

An **httpOnly cookie** is a cookie that **cannot be accessed via JavaScript** (`document.cookie`). It is only sent with HTTP requests. [code block] **Security benefits:** 1. **Prevents XSS attacks**...

Sign in to continue reading

Create a free account to unlock login-level content, or go premium for everything.

**CORS (Cross-Origin Resource Sharing)** is a security mechanism that allows servers to specify which origins can access their resources. **Same-origin policy:** Browsers block requests from one orig...

Sign in to continue reading

Create a free account to unlock login-level content, or go premium for everything.

**1. Virtual Scrolling / Windowing:** Only render elements visible in the viewport: [code block] **2. Pagination:** Load items in pages of 20-50. **3. Infinite Scroll:** Load more as user scrolls. ...

Sign in to continue reading

Create a free account to unlock login-level content, or go premium for everything.

**SSG (Static Site Generation):** - Pages generated at **build time** - Served as static HTML files - Fastest (CDN cacheable) - Use for: blogs, docs, marketing pages [code block] **SSR (Server-Side R...

Sign in to continue reading

Create a free account to unlock login-level content, or go premium for everything.

**XSS (Cross-Site Scripting)** injects malicious scripts into web pages. **Prevention strategies:** 1. **Sanitize user input:** [code block] 2. **Use textContent instead of innerHTML:** [code block...

Sign in to continue reading

Create a free account to unlock login-level content, or go premium for everything.