A Beginner’s Guide to HTTP and Web Pages

When you type a URL into your browser and hit Enter, a lot of things happen in the background to fetch and display that page. The magic behind it all is HTTP (HyperText Transfer Protocol). It is the foundation of data communication on the World Wide Web.

What Is the Web?

The World Wide Web is a system of interlinked documents and applications, accessed through the Internet using web browsers.

  • Each web page is stored on a web server.
  • Your browser (the client) sends a request to the server.
  • The server responds by sending back the requested web content (HTML, images, videos, etc.).

HTTP: The Web’s Communication Protocol

HTTP (HyperText Transfer Protocol) is the protocol used by browsers and web servers to communicate. It is:

  • Text-based (you can read the messages)
  • Stateless (each request is independent; the server doesn’t remember past interactions)
  • Usually runs over TCP (port 80 for HTTP, 443 for HTTPS)

HTTP Request-Response Cycle

When you load a web page, here’s what typically happens -

  1. Your browser sends an HTTP request to the web server (e.g., GET /index.html)
  2. The server processes the request and sends back an HTTP response containing:
    • Status code (e.g., 200 OK, 404 Not Found)
    • Headers (metadata like content type)
    • Body (actual HTML, image, etc.)

Example: Basic HTTP Request and Response

Request:

GET /index.html HTTP/1.1
Host: www.csprimer.in

Response:

HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 147

<html>
  <body>Hello, world!</body>
</html>

Persistent vs Non-Persistent HTTP

Non-Persistent HTTP

  • For each object (HTML, image, CSS, etc.), a separate TCP connection is made.
  • Slower due to repeated connection setup.

Persistent HTTP

  • One TCP connection is reused for multiple objects.
  • Reduces latency and is now the default in HTTP/1.1.

Cookies: Making HTTP “Remember”

Since HTTP is stateless, how do websites remember if you’re logged in?

Enter cookies, a small data stored on your device*(browser)* that the server can use to maintain session state.

This enables features like shopping carts, user logins, and preferences.


Web Caching: Speeding Things Up

Web caches are servers or devices that store copies of web content to reduce loading time and server load. If a requested object is in the cache (and still valid), it’s served directly and there is no need to contact the origin server.

Benefits:

  • Faster response times
  • Lower bandwidth usage
  • Reduced load on origin servers

Note - Browser itself also has a cache


HTTP vs HTTPS

HTTPS (HyperText Transfer Protocol Secure) is HTTP over TLS (Transport Layer Security). In simple words it encrypts your communication with the server. It has become a standard for all modern websites, especially those with logins or sensitive data.


HTTP Version History

VersionKey Feature
HTTP/1.0Non-persistent, no caching
HTTP/1.1Persistent connections, pipelining
HTTP/2Multiplexing, header compression
HTTP/3Runs over QUIC (uses UDP), faster

Modern browsers support HTTP/2 and HTTP/3, which significantly reduce latency and improve performance