Internet Advanced: Security, Speed and Governance
HTTP Versions, Caching and CDNs
In this lesson you will
- Explain what HTTP/2 and HTTP/3 improve
- Configure caching with Cache-Control and validators
- Describe how a CDN works and what it should cache
Introduction
A fast website is a well-delivered website. Speed depends on how many round trips are needed, how much data moves, and how close it is to the user. Three levers help: newer HTTP versions, caching, and CDNs.
The evolution of HTTP
- HTTP/1.1 sends requests one after another on a connection, so a slow response blocks those behind it (head-of-line blocking). Browsers open several connections to work around this.
- HTTP/2 keeps one connection and multiplexes many requests and responses at the same time as streams. It also compresses headers and uses a binary format. It runs over TCP with TLS.
- HTTP/3 replaces TCP with QUIC, which runs over UDP and builds in TLS 1.3. It avoids head-of-line blocking at the transport layer (a lost packet only delays its own stream), starts connections faster, and survives network changes, such as moving from Wi-Fi to mobile data.
Browsers and servers negotiate the best version automatically, so most sites need only a server or CDN that supports them. The meaning of HTTP (methods, status codes, headers) stays the same.
Quick quiz
What does HTTP/2 multiplexing allow?
Caching: the fastest request is the one never made
A cache keeps a copy of a response for reuse. Browsers, CDNs and servers all cache. You control it with response headers.
Cache-Control is the main one:
Cache-Control: public, max-age=31536000, immutable
Cache-Control: no-cache
Cache-Control: no-store
Cache-Control: private, max-age=0max-age=Nmeans it may be reused for N seconds without asking the server.publicallows shared caches such as CDNs.privateallows only the user's browser.no-cachemeans "you may store it, but check with the server before each reuse".no-storemeans do not store it at all, and is used for sensitive data.immutablesays the file will never change at this address.
Validators make rechecking cheap. The server sends an ETag (a fingerprint) or Last-Modified. The browser later asks "has it changed?" with If-None-Match. If not, the server replies 304 Not Modified with no body.
A practical strategy
- Fingerprint static files (such as
app.3f9a2c.js) and cache them for a year withimmutable. A new version has a new name. - Serve HTML with a short or revalidated cache, so users get updates quickly.
- Never cache private or personalised responses in shared caches.
Content delivery networks
A CDN is a network of servers in many cities. Users are routed to a nearby one.
- The first user in a region requests a file. The CDN fetches it from your origin server, stores it and serves it.
- Later users nearby get it straight from the CDN's edge, with low latency, and your origin does little work.
Benefits: speed, less load, resilience to spikes, DDoS absorption and automatic HTTP/3 and TLS support. Many CDNs also run code at the edge, optimise images and offer a web application firewall.
Things to manage:
- Cache keys: what makes two requests "the same" (the path, query string, headers).
- Purging: removing outdated copies, easiest when files are fingerprinted.
- Do not cache logged-in pages unless you know exactly how.
- Origin protection: make sure the origin accepts traffic only from the CDN where possible.
Other speed tips
- Compress text with gzip or Brotli.
- Use modern image formats and the right sizes.
- Reduce and defer JavaScript, and load the important content first.
- Preconnect and preload important resources.
- Measure with real-user data and tools such as Lighthouse and the browser's Network panel, focusing on loading speed, responsiveness and visual stability.
Try it yourself
Open the browser developer tools on a website. In the Network panel, look at the response headers for one image and one HTML page. Which caching headers do they use, and which HTTP version was used?
Summary
- HTTP/2 multiplexes requests on one connection, and HTTP/3 uses QUIC over UDP for faster, more resilient connections.
- Cache-Control, ETag and fingerprinted file names let browsers and CDNs reuse responses safely.
- CDNs serve content from nearby edges, cutting latency and origin load, and need careful cache rules.
Lesson complete
+20 XP
Nice work. Keep going while it is fresh.
Sources and further reading