Demo mode This site is not live. It is currently being tested and developed. Nothing on here represents an offer.
← Exit course WEB-201 Front-End Web Development with JavaScript
Course progress, 0 of 9 parts done0%
Practical work

5 tasks, about 7.5 hours

Download as PDF

Set up a workstation and project folder from the terminal, take URLs apart and look up DNS names, read raw HTTP with curl, measure a real page in the Network panel and trace cookies through a real login.

This week you set up a professional workstation and become fluent in reading the conversation between browser and server. Keep your findings in notes/module-1.md in your Walk Planner folder: each task says what to record. You need Chrome or Edge, and Firefox if you have it. Together the five tasks take about seven and a half hours.

Task 1: Set up your workstation and the project folder

  1. Open a terminal (Windows Terminal or PowerShell on Windows, Terminal on Linux Mint). Run pwd, then list your home folder's contents, including hidden files.
  2. Using only the terminal, create the Walk Planner folder structure from the lesson in a projects folder in your home folder, with an empty index.html, css/styles.css and notes/module-1.md. Open it in VS Code with code ..
  3. Set VS Code to format on save and to auto save when the window loses focus. Open the integrated terminal and check that its working directory is your project folder.
  4. Check that Git and curl are installed with git --version and curl --version (curl.exe --version on Windows). Install whichever is missing, and set your Git name, your GitHub noreply email address and the default branch name main.
  5. In index.html, use Emmet to create a page skeleton, set lang="en-ZA" and the title "Walk Planner, Mandla's Mountain Walks", and add an h1. Open it in the browser.
  6. In your notes, write the absolute path of index.html, then the relative path from index.html to css/styles.css and from notes/module-1.md to index.html.

What you produce: the project folder made from the terminal, a page skeleton that opens in the browser, VS Code configured, Git and curl working, and your three paths in your notes.

Time: 1 hour 30 minutes.

Task 2: Take URLs apart and look up names

  1. Find a real URL of each of these kinds and paste it into your notes: a search results page (for example a search on a South African online shop), a page reached through a contents link that has a fragment, a map or directions link, a news article, and a video link with a start time.
  2. For each, make a table with its scheme, host, port (written or default), path, query string as separate name and value pairs, and fragment. Write "none" for any part it does not have.
  3. For each query string, say in a sentence what you think each name and value does, then test your guess by changing one value in the address bar and seeing what happens.
  4. Run nslookup for three South African sites: a government site, a bank and a small business you know. On Linux Mint, if nslookup is missing, install it with sudo apt install bind9-dnsutils. Record each IP address, and note any CNAME (shown as "canonical name" or "Aliases").
  5. Run nslookup for a name that does not exist, and record the exact message. Then type that name into the browser and record what the browser shows. Explain in two sentences why there is no status code.

What you produce: five URLs broken into their parts with your tested explanations of their query strings, and a DNS record for three real sites and one that does not exist.

Time: 1 hour 15 minutes.

Task 3: Read raw HTTP with curl

  1. Run curl -I on the home pages of the three sites from Task 2. For each, record the status code, Content-Type, Cache-Control and Server headers, and any Set-Cookie header's cookie name and attributes (never its value).
  2. Run curl -IL on the http:// address (without the s) of each site. Record each status code and Location in the chain, and count the redirects.
  3. Find a page on one of the sites that does not exist (make up a path) and record its status code with curl -I. Does the site send a real 404, or a 200 with a "not found" page? Explain why the difference matters for search engines.
  4. Run curl -v https://example.com/ -o page.html. In your notes, copy the lines that show the request curl sent (starting with >) and label the method, path, protocol version and each header.
  5. Send a POST with form data to https://httpbin.org/post, as in the lesson, with two values of your own. Find your values in the reply. Then send a GET to the same address and record the status code you get, and what it means.

What you produce: a record of the headers and redirect chains of three sites, a test of how one site handles a missing page, a labelled raw request, and your POST and GET results from httpbin.

Time: 1 hour 30 minutes.

Task 4: Investigate a real page with the Network panel

  1. Choose a busy South African news or shopping site. Open it in Chrome or Edge with the Network panel open, Disable cache ticked and no throttling, and reload. Record the number of requests, the amount transferred and the finish time from the bottom bar.
  2. Sort by size and list the five largest files with their type, size and, for images, the size shown on the page compared with the image's real size (Preview shows the real size).
  3. Use the filter buttons to count the CSS, JavaScript, image and Fetch/XHR requests. Click one Fetch/XHR request and describe what data it fetched.
  4. Untick Disable cache and reload. Record what changed in the transfer total and which files now show a cache or 304.
  5. Tick Disable cache again, set throttling to Slow 4G, reload and record the finish time. Pick the slowest request and use its Timing tab to say which stage took longest.
  6. Write a short report of about 300 words for the site's owners: the three changes that would speed the page up most for a visitor on a phone, each supported by a number you recorded.

What you produce: your measurements of a real page with and without the cache and throttling, and a 300-word performance report with evidence.

Time: 1 hour 45 minutes.

Task 5: Trace cookies and a login

  1. Open a site you log in to, such as your email, a bank or a shop, and open the developer tools. In Chrome or Edge choose Application, then Cookies. In Firefox choose Storage, then Cookies. Without recording any values, list up to eight cookies' names with their Expires or Max-Age, HttpOnly, Secure and SameSite settings.
  2. Decide which cookie is most likely the session cookie, and give two reasons from its attributes.
  3. With the Network panel open and Preserve log ticked, log out and log back in. Find the request that sent your login details: record its method and status code, and whether its response had a Set-Cookie header (name only). Do not copy the request body, which contains your password.
  4. Find the next request after logging in and check that the session cookie's name appears in its Cookie request header.
  5. Draw the login conversation for this site as a simple sequence diagram on paper or in your notes, like Figure 1.3, using what you actually saw.

What you produce: a table of cookie names and attributes (no values), your identification of the session cookie with reasons, and a sequence diagram of a real login.

Time: 1 hour 30 minutes.

Show the model answer

Task 1: Set up your workstation and the project folder

Your folder should look like this when listed with ls -R on Linux Mint, or Get-ChildItem -Recurse on Windows:

Terminal, model answer
walk-planner/
  index.html
  css/styles.css
  js/
  images/
  data/
  notes/module-1.md

A model skeleton for index.html:

index.html
<!doctype html>
<html lang="en-ZA">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Walk Planner, Mandla's Mountain Walks</title>
</head>
<body>
  <h1>Walk Planner</h1>
</body>
</html>

The paths, for a learner called Lerato on Linux Mint: the absolute path is /home/lerato/projects/walk-planner/index.html (on Windows, C:\Users\Lerato\projects\walk-planner\index.html). From index.html to the stylesheet is css/styles.css. From notes/module-1.md to index.html is ../index.html, because you go up out of notes first.

If code . is "not recognised" on Windows, close and reopen the terminal after installing VS Code. On Linux Mint, if Emmet's ! does nothing, check the file is saved with the .html extension, so VS Code knows it is HTML.

Task 2: Take URLs apart and look up names

A model breakdown of one URL, a search on an online shop:

One URL, taken apart
PartValue
Schemehttps
Hostwww.example-shop.co.za
Portnone written, so the default 443
Path/search
Query stringq = hiking boots (sent as hiking%20boots or hiking+boots), sort = price_asc, page = 2
Fragmentnone

A good explanation tests each guess: "Changing page=2 to page=3 showed the next page of results, so page chooses the page of results." Video links usually carry their start time in the query string, such as t=95 on YouTube, while contents links in articles use a fragment, such as #History.

For a name that does not exist, nslookup reports something like ** server can't find www.mandlaswalks.co.za: NXDOMAIN on Linux Mint, or "Non-existent domain" on Windows. The browser shows its own page, such as "This site can't be reached" with DNS_PROBE_FINISHED_NXDOMAIN in Chrome, or "Hmm. We're having trouble finding that site." in Firefox. There is no status code because the browser never found a server to send a request to, and status codes come only from servers.

IP addresses change and large sites often answer with several, and with different ones in different places, because they use content delivery networks. That is expected, not an error.

Task 3: Read raw HTTP with curl

A typical record for a government home page looks like this (your values will differ):

Terminal, model answer
$ curl -I https://www.gov.za/
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Cache-Control: max-age=3600, public
Server: CWAF

max-age=3600, public means any cache, including the browser's, may keep the page for an hour. A Set-Cookie line, where present, should be recorded as, for example, "a cookie named SSESS..., with Secure, HttpOnly and SameSite=Lax".

For the http:// address, a good site gives one redirect: a 301 or 302 with Location: https://..., then 200. Two or more redirects, for example http to https, then the bare domain to www, then to a home page path, each cost the visitor a round trip, which matters most on a slow phone connection.

For a made-up path, a well-built site returns 404. Some return 200 with a "page not found" message, called a soft 404. That tells search engines the page exists, so they may list a useless page, and it tells monitoring tools that nothing is wrong.

The request lines from curl -v look like this, with the parts labelled:

Terminal, model answer
> GET / HTTP/2                   method GET, path /, protocol HTTP/2
> Host: example.com              which site
> User-Agent: curl/8.5.0         which client
> Accept: */*                    any format is acceptable

The POST to httpbin replies with JSON in which your values appear under "form", for example "walk": "lions-head", and the Content-Type header curl sent, application/x-www-form-urlencoded, appears under "headers". A GET to https://httpbin.org/post returns 405 Method Not Allowed: that address only accepts POST.

Task 4: Investigate a real page with the Network panel

Busy news and shopping home pages commonly make 100 to 300 requests and transfer 3 to 10 MB on a first visit with the cache disabled. On a repeat visit with the cache on, the transfer total typically falls by more than half, because stylesheets, scripts, fonts and logos come from the disk cache or return 304. Advertising and tracking requests often make up a large share of the total, and they rarely cache.

A strong report gives specific, measured recommendations, for example:

  • "The three largest images are 1.8 MB, 1.2 MB and 0.9 MB but are shown at about 400 pixels wide. Serving them at the size shown, in a modern format such as WebP, would save about 3.5 MB, roughly 40% of the page."
  • "The page loads 64 JavaScript files totalling 2.1 MB, 1.3 MB of them from advertising and analytics services. Loading those after the main content would let a reader start reading sooner."
  • "On Slow 4G the page finished in 48 seconds. The slowest request spent 3.2 seconds waiting for the server's first byte, so the server side needs attention as well as the file sizes."

Each recommendation names the problem, gives the number that proves it, and says what would change. "The site is slow and should be faster" is not a finding.

Task 5: Trace cookies and a login

A good cookie table records attributes only, for example:

Cookies on a site you log in to (names and attributes only)
NameExpires or Max-AgeHttpOnlySecureSameSite
sessionidSessionYesYesLax
csrftoken1 yearNoYesLax
_ga2 yearsNoNonone set

The session cookie is usually the one that is HttpOnly and Secure, has a name such as session, sid or PHPSESSID, and either ends with the browser session or has a short lifetime. Analytics cookies, such as Google Analytics' _ga, last for months or years and are readable by scripts, because the analytics script itself reads them.

The login request is almost always a POST. It commonly returns 302 (a redirect to your account page) or 200, and its response includes a Set-Cookie for the session cookie. The very next request carries that cookie's name in its Cookie header. Some sites log in with a script instead, in which case the login request appears under Fetch/XHR and returns JSON. Your diagram should match what you saw, not the textbook: if the site redirected twice, draw both redirects.