Static Site Deployment
Introduction
Your HTML files work locally, but the web expects HTTP. Deployment means putting your static files on a server or hosting platform so anyone can visit them with a URL. This chapter compares local preview, static hosts, and Nginx on Linux, plus MIME types, 404 pages, and caching basics.
Prerequisites
Local File vs HTTP Server
Opening a file directly:
file:///Users/you/my-site/index.htmlProblems:
- paths behave differently than on a real site
- some features (modules, fetch, certain APIs) may fail
- share URLs are impossible
Serving over HTTP:
http://127.0.0.1:5500/index.htmlUse Live Server, npx serve, or Python's built-in server while developing:
# Serve current directory
npx serve .
# Python 3
python3 -m http.server 8000Then open http://localhost:8000/.
Tip
Deploy What You Tested Over HTTP
Preview with a local server before upload. It catches path and MIME issues early.
What Static Hosting Needs
A static deploy is usually:
- Upload HTML, CSS, JS, images, and fonts.
- Point a domain at the host.
- Ensure
index.htmlis at the site root (or configured default). - Serve correct MIME types for each file extension.
No database or Java server is required for pure static sites.
GitHub Pages (Concept)
Good for portfolios and docs:
- Push site files to a GitHub repository.
- Enable Pages in repository settings.
- Choose branch and folder (
/rootor/docs). - Visit
https://username.github.io/repo-name/.
Watch relative paths if the site is served from a subpath:
<!-- May need a base path or absolute paths from site root -->
<link rel="stylesheet" href="/my-repo/css/styles.css">Read the host docs for project pages vs user/org sites.
Netlify and Vercel (Concept)
Both support drag-and-drop or Git-connected deploys:
| Step | Action |
|---|---|
| 1 | Connect repository or upload folder |
| 2 | Set build command (often empty for plain HTML) |
| 3 | Set publish directory (. or dist) |
| 4 | Deploy |
They provide HTTPS, CDN, and preview URLs for branches. Forms and server logic need serverless functions or external services.
Nginx on Linux
For a VPS, Nginx can serve files directly. See also Linux and Nginx topics in the Linux track.
Minimal site config idea:
server {
listen 80;
server_name example.com;
root /var/www/my-site;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}Place built files in /var/www/my-site/:
/var/www/my-site/
├── index.html
├── about.html
├── css/
├── js/
└── images/Reload Nginx after config changes. Use HTTPS (Let's Encrypt) in production.
MIME Types
Browsers use MIME types to interpret files:
| Extension | MIME type (typical) |
|---|---|
.html | text/html |
.css | text/css |
.js | application/javascript |
.png | image/png |
.webp | image/webp |
.svg | image/svg+xml |
.pdf | application/pdf |
Wrong MIME type symptoms:
- CSS downloads instead of applying
- JavaScript shown as plain text
- images fail to render
Major hosts configure common types automatically. Custom servers may need explicit types blocks.
Custom 404 Page
When a URL is missing, return a helpful page:
Host configuration varies:
- GitHub Pages:
404.htmlat root - Netlify/Vercel:
404.htmlin publish directory - Nginx:
error_page 404 /404.html;
Caching Basics
Browsers cache static files to speed repeat visits. Servers send headers like:
Cache-Control: max-age=3600For HTML you are actively editing, short cache or no cache helps you see updates. For hashed asset filenames (app.a1b2c3.css), long cache is safe because the URL changes when content changes.
As a beginner:
- hard refresh after deploy (
Cmd+Shift+R/Ctrl+Shift+R) - check DevTools Network Disable cache while debugging
- purge CDN cache if your host uses one (production issue)
Pre-Deploy Checklist
- All internal links work
- Images and CSS return 200 in Network panel
- Unique
<title>per page -
meta descriptionon important pages -
faviconpresent (optional) -
404.htmlexists (optional) - No references to
localhostin production HTML - HTTPS enabled on production domain
- Case-sensitive paths match uploaded file names
Mini Exercise
Deploy your chapter 35 site to one free static host:
- Zip or push the project folder.
- Deploy and note the public URL.
- Open every page from the live URL.
- Fix any broken asset paths.
- Share the link and confirm Open Graph preview if you added OG tags.
FAQ
Do I need Node.js to deploy static HTML?
No for plain HTML. You only need Node if you use a build tool or dev dependencies locally.
Why does my site work locally but not online?
Common causes: wrong relative paths, wrong base path on GitHub Pages, missing files in upload, or case mismatch (About.html vs about.html).
Can I host only HTML without a domain?
Yes. Hosts give you *.github.io, *.netlify.app, or similar URLs.
Does deployment include forms?
Static hosting serves files. Forms need a backend, form service, or serverless handler.
What comes next?
HTML resources and book recommendations — where to learn more after this track.