Skip to content

Hosting a Static Site

If you've decided a static site is right for your project, there are a few steps you'll need to follow to publish your site.

  1. Build the HTML.
  2. Pick a host and publish your files.
  3. Point DNS records at the host.

Static Site Generators

If you are writing HTML and JS yourself and have a working site you just want to host, you can skip this section.

Often sites are composed of dozens or hundreds of similar pages: blog posts, image galleries, etc. Writing the HTML by hand would be repetitive and tedious. Many turn to a dynamic site here, a blog engine like WordPress or Ghost that can dynamically generate pages from content stored in a database.

As discussed in the section on deciding between static and dynamic hosts, this switch comes with real costs in complexity and dollars.

An alternate option is to use a static site generator (SSG), a tool that takes content authored in a simpler form (typically Markdown) and generates HTML files for each page on the site.

This site is an example of this approach; the content for this site lives in a git repository and is converted from Markdown to HTML via Zensical, a static site generator.

Unlike other areas, it is hard to give a single recommendation. There are many SSGs, each with their own quirks. (For a long time writing your own was a rite of passage for a junior developer, in part due to how idiosyncratic most people's preferences can be.)

The right SSG for a given project is a function of the kind of site you want to build, your preference of templating language, and what language ecosystems you are most familiar with.

A few recommendations:

Choices?

There are a lot of choices to make: registrar, host, operating systems, various third-party services. It can be overwhelming.

To help, our guides typically make a general recommendation that we think is a safe choice for most people as well as a few alternatives to consider.

Our resource guide also provides other reasonable choices you can consider.

Previewing Your Site

As you work on your site with an SSG, you'll run a dev server allowing you to see your markdown files as rendered output.

Or, if you aren't using an SSG, you may want to use a tool that creates a generic server that will serve static files locally and autoreload when a file changes:

Publishing Static Files

However your HTML, CSS, and JavaScript are created, all that needs to be done to make your site public is put those files somewhere that the world can access them.

Unlike dynamic applications which require running custom code, typically with a database and other supporting services, all a server needs to do to host your content is send those files to users when requested.

There are lots of free and affordable options. Free options often enshittify rapidly, but if you're using your own domain it is easy enough to move.

Free options:

Another approach is to use a CDN (content delivery network) which can let you host low to moderate traffic sites for between $0 and $1/month. These services are less likely to disappear or change their terms forcing a migration. Some CDNs well-suited to this purpose:

  • bunny.net: An EU-based CDN; you can host a nearly unlimited number of sites for $1/month.
  • Fastly: One of the most popular CDNs; has a free tier that should cover most low traffic sites. Requires a credit card on file.

The downside is that using a CDN isn't as straightforward1 as dedicated static site hosts.

trifold

To help address that need, trifold is a tool we created to make publishing your static site to a CDN under your control as easy as running trifold publish. After a one-time config, the tool handles uploading your files, obtaining SSL certificates, and managing redirects.

See trifold quickstart to get started.

Pointing DNS at your Host

After following the steps above, your files are now hosted at a domain like https://example.b-cdn.net or https://example.github.io. While this works for simple sites, or for testing, you probably want to own your own domain. This comes with many advantages, among them the ability to switch hosts2 without breaking links to your site.

If you haven't already, brush up on Managing DNS to understand the terms used in this section.

There are typically two steps to using your own domain:

  1. On your registrar, configure the DNS to point a subdomain to your hosted site. (e.g. a CNAME3 pointing example.view-source.org -> view-source-example.b-cdn.net)
  2. On the static host or CDN: enable the new domain name(s) you wish to use. For example:

Note that DNS changes can take a bit of time to propagate, typically a few minutes, but sometimes a day or so. If your site doesn't work right away, check the settings first, and then wait a few hours and/or try different devices and networks.

Once this is done, any updates you publish to your static site will be reflected on your domain. Congratulations, you're publishing on the web!


  1. Bunny now has their own CLI for managing sites: bunny.net sites cli. ↩

  2. You may find yourself wanting to switch hosts for a number of reasons: cost, policy, reliability/quality of service. ↩

  3. If you want to host your base domain: view-source.org instead of www.view-source.org or similar, you'll need to use an ALIAS or A record instead of a CNAME per instructions from your provider. ↩