How a static site works
- Site generatorAstro, Eleventy, Hugo
- Finished filesHTML, CSS and JavaScript
- Any host or CDNSimply serves the files
- Fast pagesNo server code to wait for
What it can and cannot do
Works well
- Content
- Blogs, docs and marketing sites
- Interaction
- Portfolios and landing pages
- Delivery
- Fast global delivery with a CDN
Needs something extra
- Content
- Search (use a client-side index or service)
- Interaction
- Contact forms (use a form service)
- Delivery
- User accounts and logins
Where to host it
- Any shared hostUpload the built files to the public folder.
- Static platformsConnect Git and deploy on every commit; many have free tiers.
- A VPSServe the files with a web server such as Nginx.
Check bandwidth and build limits on free tiers, whether commercial use is allowed, and what happens when you exceed a limit.
How do you deploy a static site?
- Build the site
Generate the files with your tool.
- Upload or connect git
Copy files or let a platform build.
- Set the domain and HTTPS
Point DNS and enable a certificate.
- Set caching and redirects
Use long cache times for assets.
What should you check?
- Free tier limits for bandwidth and builds.
- Redirect, header and form support.
- CDN coverage; see what a CDN is.
- How preview deployments work.
When do you need more than static hosting?
When you need server-side logic, a database or user accounts. Add serverless functions or use a server; see hosting for Node.js and hosting for portfolio sites.
How do the main hosting options compare?
| Option | Good for | Notes |
|---|---|---|
| Static platform with git deploys | Developers who want previews and automation | Free tiers; limits on builds and bandwidth |
| Object storage with a CDN | Cheap, scalable file hosting | You set up redirects, headers and HTTPS |
| Classic shared hosting | Simple uploads by SFTP | Fine for small sites; few automation features |
| A VPS with a web server | Full control | You manage the server |
How do you add forms, search and dynamic features?
A static site has no server code, but you can add features with services and functions. Use a form service or a serverless function for contact forms, a search index built at deploy time or a hosted search service for search, and a headless CMS for editing; see hosting a headless CMS. Keep secrets out of client-side code and check each service’s limits and pricing.
What caching headers should you set?
Give fingerprinted assets, files whose names change when content changes, a long cache lifetime, and give HTML a short one or require revalidation, so updates appear quickly while images and scripts stay cached. MDN’s guide to HTTP caching explains the headers, and a CDN, covered in what a CDN is, follows them.
What are the common mistakes?
- Caching HTML for too long, so updates do not appear.
- Forgetting redirects when URLs change; see subdomain vs subfolder for migration steps.
- Putting secrets in client-side code.
- Ignoring a platform’s bandwidth or build limits until a bill arrives.
- Leaving the custom domain without HTTPS; see what an SSL certificate is.