1.3 Understanding Modern Websites
HTTP is a stateless protocol: it doesn’t know who you are or where you’ve been. It knows only what you’ve just asked it for. In the early days of the Internet, each webpage on a site was a file, such as a text file or a PDF. Websites were static.
Today, many websites are dynamic. We now interact with websites: instead of just asking the server to send us a file, we write comments on videos, blog about the best web framework ever, and tweet cat pictures to our friends. To enable these activities, webpages must be generated (computed) for each user based on new and changing data. We’ve had to add a number of technologies on top of HTTP to determine state (such as sessions, which we’ll see in Chapter 19: Basic Authentication), and we now have entire languages and systems (like Django!) to make the dynamic generation of webpages as easy as possible. Our original HTTP loop now has an extra step between the request and response, as shown in Figure 1.3.
Figure 1.3: HTTP Request/Response Cycle Diagram
This dynamic generation of webpages is referred to as back-end programming, as opposed to front-end programming. Front-end programming involves creating the behavior of the webpage once it has already been generated by the back end. We can think of the combined experience in four steps:
- A user’s browser issues a request for a page.
While front-end programming certainly provides for a dynamic experience, the words dynamic webpage typically refer to a webpage that is computed on the back end. It can be difficult to distinguish the difference between front-end and back-end programming because modern websites strive to blur the difference to create a more seamless user experience. In particular, websites known as single-page applications blur this line to the point that step 2 is seriously mangled. However, the distinction is still important, as the HTTP protocol remains between the user and the server and the tools for front-end and back-end programming are typically quite different.