Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Fix Paths That Break Online

A site can look right in your local preview and still have paths that break once it’s published. This lesson follows one missing photo from the preview to GitHub Pages, finds the cause in DevTools’ Network panel, and fixes it.

Key Points

  • A local preview doesn’t prove your paths. If you published the garden, every page may well look right online, and you don’t need to upload anything here: the video shows a demonstration copy of the garden. On it, the seed swap page’s photo tag asks for ../images/Seed-swap.jpg, with a capital S, while the file is images/seed-swap.jpg. In the editor’s live preview on macOS or Windows, the photo shows. At the GitHub Pages address, the page loads with its styles, but the photo is replaced by a broken image icon and its alt text.
  • HTML doesn’t report errors, so the page alone won’t tell you why. Open DevTools, choose the Network panel, and reload, because the panel records only while it’s open. Each row is one file the page asked for, with the server’s answer: 200 means found, 404 means not found. The page and style.css show 200, and Seed-swap.jpg shows 404.
  • Why: the browser sends the exact name, and each server asks its own computer’s file system for that file. GitHub’s file system, like Linux’s, matches names letter for letter, so Seed-swap.jpg is a different name, and no file has it. On macOS and Windows, the file system ignores letter case by default, so the preview found the lowercase file anyway. On Linux, the preview would fail too.
  • The fix: the garden keeps its file names lowercase, so fix the path rather than renaming the file. Change the src to match the file’s name, then upload the fixed page, seed-swap.html: in the repository, open the events folder, use Add file, then Upload files, and click Commit changes. A file with the same name replaces the old one. Wait for the deployment to finish, which can take several minutes. Then hard reload, with Ctrl+Shift+R, or Cmd+Shift+R on a Mac, so the browser asks the server again. The photo’s row shows 200, and the photo is back.
  • Paths that start with a slash start at the root. In your preview, the garden folder is the root, so they work. Online, the root is the domain, outside your garden folder, so <link rel="stylesheet" href="/style.css"> in garden/index.html asks for the domain’s own style.css and gets a 404. The garden’s paths are relative to the page (style.css from garden/index.html, ../style.css from events/seed-swap.html), so they keep working.
  • Watch out: Pages runs your files through a tool called Jekyll, which skips files and folders whose names start with an underscore (_). An empty file named .nojekyll at the top of the repository turns Jekyll off.
  • The rule: keep file names lowercase, match them letter for letter, and check every published page in the Network panel for 404 errors.

Final Code

The seed swap page’s photo, in events/seed-swap.html, with its src matching the file’s name letter for letter:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 If you published the garden, every page may well look right online. However, paths can still break once a site is published.

00:09 In this video, you’ll watch a demonstration copy of the garden, where one photo shows on your computer and goes missing online. You’ll find out why with the Network panel, and fix it.

00:21 On this copy, the seed swap page’s photo tag points at the seed swap photo in the images folder. Open the page in your editor’s live preview on a Mac or a Windows computer, and the photo shows.

00:33 So the copy goes up to GitHub Pages unchanged.

00:38 At the Pages address, the page loads with its styles, but the photo is gone. In its place, there’s a broken image icon and the alt text. HTML doesn’t report errors, so the page alone won’t tell you why.

00:53 Open DevTools, choose the Network panel, and reload, because the panel records only while it’s open. Each row is one file the page asked for, with the server’s answer.

01:03 The page and the stylesheet show 200, found. The photo’s row shows 404, not found.

01:12 The images folder has a seed swap photo, though. Compare the name the page asked for with the file’s name. What’s different? Your turn: pause the video and predict.

01:28 The first letter. The page asked for a capital S, and the file has a lowercase s.

01:36 The browser sends the exact name, and each server asks its own computer’s file system for that file. GitHub’s file system, like Linux’s, matches names letter for letter.

01:47 A capital S is a different name, and no file has it. On macOS and Windows, the file system ignores letter case by default, so the preview found the lowercase file anyway.

01:58 On Linux, the preview would fail too.

02:03 The garden keeps its file names lowercase, so fix the path. In the photo tag, change the capital S to a lowercase s, to match the file. When this happens on your site, upload the fixed page.

02:16 In the repository, open the events folder, use Add file, then Upload files, and commit. A file with the same name replaces the old one. Wait for the deployment to finish, which can take several minutes.

02:30 Then hard reload, with Ctrl+Shift+R, or Cmd+Shift+R on a Mac, so the browser asks the server again. The photo’s row now shows 200, and the photo is back.

02:45 Letter case isn’t the only difference. A path that starts with a slash starts at the root. In your preview, the garden folder is the root, so it works. Online, the root is the domain, outside your garden folder, so a stylesheet linked that way is a 404.

03:00 The garden’s paths are relative to the page, so they keep working. Watch out for files and folders whose names start with an underscore, too. Pages runs your files through a tool called Jekyll, which skips them.

03:13 An empty file named .nojekyll at the top turns Jekyll off.

03:20 So a local preview doesn’t prove your paths. Keep file names lowercase, match them letter for letter, and check every published page in the Network panel for 404s.

03:31 Next, in Exercise: Prepare the Work Day Page, you’ll get the work day page ready to go online.

Become a Member to join the conversation.