Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
How a Full-Stack App Fits Together  ›  Capstone Project

Pages or Data: Who Builds the HTML?

JavaScript 14 minA server can answer with a finished HTML page or with JSON that JavaScript turns into a page in the browser, and the right choice depends on whether a page serves searchable public visitors or logged-in interactive users.

Pages or Data: Who Builds the HTML?

Two web apps can look identical and still split the work in opposite ways. In one, the server sends finished HTML and the browser simply shows it. In the other, the server sends raw data and JavaScript in the browser builds the page. Sprout could be built either way, so it is worth knowing what each choice buys.

The rule

Either the server sends a finished page, or it sends data and the browser builds it.

Server-rendered. A request for /plants runs a query on the server, pours the rows into an HTML template and returns a complete page with Content-Type: text/html:

<ul>
  <li>Fern, water every 3 days</li>
  <li>Cactus, water every 21 days</li>
</ul>

Every click that moves to another page asks the server for another finished page.

Client-rendered. The first response is a small HTML shell plus a JavaScript bundle. Once loaded, the JavaScript calls an API such as /api/plants and receives only data:

[{"id": 7, "name": "Fern", "water_every_days": 3},
 {"id": 9, "name": "Cactus", "water_every_days": 21}]

The browser turns that JSON into the list itself. From then on, only data travels.

Server sends HTML Server sends JSON
First view content arrives in the first response waits for the script, then the data
Search engines see the content directly may see an empty shell
After loading a new page per navigation small data requests; feels like an app
A future phone app needs a separate API reuses the same API

Many modern frameworks mix the two: they render the first view on the server, then let JavaScript take over in the browser. The question "who builds this HTML?" still decides where each piece of code runs.

This course builds Sprout's logged-in screens as a React client over a JSON API. Those screens sit behind a login, so search engines never see them anyway, and the same API can later serve a phone app.

The shortcut

To see which kind of page you are looking at, open the Network tab and read the response that carries the main content: HTML with your data inside means the server built it; JSON means the browser will. To choose for a new page, ask: "Who is this page for: strangers arriving from search, or a logged-in user clicking around?"

Choosing for each Sprout pageStep 1 of 4
  1. Welcome page

    Public, should appear in search results, the same for everyone. Static or server-rendered HTML.

Drills

Answer fast — trust the rule.

quick drill

A response to GET /plants has Content-Type: text/html and contains <li>Fern, water every 3 days</li>. How was the list built?

quick drill

What does a client-rendered app's first HTML response usually contain?

quick drill

Sprout plans an Android app. Which design lets it reuse the most server code?

quick drill

Why is Sprout's logged-in dashboard a good fit for client rendering?

Remember

  • Either the server sends a finished page, or it sends data and the browser builds it.
  • Shortcut: public and searchable leans to server HTML; private and interactive leans to a JSON API.
  • Trap: choosing one style for the whole site. Decide page by page, and keep the API reusable.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainGuides and dashboard

Sprout has public plant care guides (articles such as 'Watering succulents') and a logged-in dashboard where users water, rename and delete plants. Explain which you would render on the server and which you would build in the browser from JSON, giving at least two reasons for each.