Building the page: on the server or in the browser
A web page can be built on the server or in the browser. The choice changes how fast the first screen appears and how much data travels.
You open a food delivery app in your browser and click through categories and menu items. On some sites the whole page goes blank and redraws after every click. On others only the list changes, and the header and the search box stay where they are.
Read the two cards. Each one shows where the page is built and what travels when you click.
Every click fetches a whole new page
The server fills in a template and sends a complete page. The browser replaces the old one.
One page, then only data moves
The first load brings a shell and a large bundle of JavaScript. Later clicks fetch only data.
More detail
Server-rendered page, the older model
The server fills in a template (a page layout with blanks), produces finished HTML (the language that describes a web page), and sends a complete document. The browser discards the old page and draws the new one. Many older sites work this way.
Single-page app, the newer model
The first load fetches an almost empty shell and a large bundle of JavaScript (code that the browser runs). After that, each click fetches JSON, and the browser updates only the parts of the DOM that changed. The DOM is the browser's live model of the page. Nothing else reloads.
The same two menu items can be sent as JSON, XML or HTML. Select each format and read its size in bytes. The blue part of each bar is the data itself and the gray part is packaging.
More detail
The text of each format
The information is the same each time: six values, 32 characters of data. Only the packaging differs. Each size counts the text with its line breaks and indentation removed. HTML is the format for web pages, and XML wraps every value in named tags.
A student opens your app, views some pages and leaves. Drag the slider to change how many pages they view, and watch which model has moved less data.
More detail
The numbers behind the bars
The model uses 45 KB of HTML per server-rendered page, a 280 KB bundle for the single-page app, and 4 KB of JSON per navigation after the first load. Stylesheets and scripts are counted once because the browser caches them, which means it keeps a copy.
Most people leave after one or two pages. Drag the slider there and check which model wins. A single-page app also suits a brochure site (a site of a few fixed pages) poorly.
Decide which kind of project yours is. If it is mostly pages that people read, server-rendered pages have fewer parts and a faster first screen. If people use it for twenty minutes, clicking around, a single-page app makes up its download cost after about seven pages.
You can now choose between the two ways of building a page for a project.
More detail
What most student projects do
Most student projects are the first kind and get built as the second kind, because tutorials show that approach. Django (a Python web framework) builds server-rendered pages by default. Choose based on how long users stay and how many pages they open.
What each choice costs elsewhere
Rendering moves to the user's device
A single-page app has the browser build the page, so your server no longer does that work. That raises the capacity ceiling covered in Server capacity, using hardware you did not buy.
→ See Server capacity. It uses the user's battery.The first screen is slower
Server-rendered HTML is ready to draw when it arrives. A bundle has to download, load and run before anything appears, and then it fetches its data.
→ See Round trips and latency. The cost is now on the client.You rebuild what the browser did for free
The back button, scroll position, the address bar and opening a link in a new tab all work by default on server-rendered pages. A single-page app has to implement each one.
→ Easy to miss until it breaksXML is heavier than JSON
XML adds rules (schemas) and labels (namespaces and attributes) that JSON does not have, so it is larger. Banks and government systems still use it, for example in SOAP messages, which are an XML message format.
→ See Payments and gateways. Larger on the wire, with stricter rules.