You have a built static site sitting in dist/. You want it on a real URL with HTTPS, in 10 minutes, without reading the full Firebase docs. This walkthrough does exactly that — and tells you which steps you can safely skip.
Background
Firebase Hosting is one of the fastest ways to put a static site on the open internet with free SSL and a global CDN. The official quickstart works, but skips a few details (cache headers, trailing slash, preview channels) that you will eventually hit. This article covers them up front so you do not have to redo the setup later.
Before you start
- A Google account and access to the Firebase console.
- A static site repo that can build locally, for example Astro / Vite / Hugo / plain HTML.
- Node.js and npm available in your terminal;
node -vandnpm -vshould both print versions. - A build command and output directory you understand, usually
npm run buildanddist. - Optional but recommended: a domain you control and access to its DNS settings.
Step by step
- Create the Firebase project first: open the Firebase console, click “Add project”, enter a project name, keep or disable Google Analytics based on whether you need it, then finish project creation.
- Open the new project, go to Build > Hosting, click “Get started”, and leave that browser tab open. You do not need to copy the whole quickstart, but it confirms Hosting is enabled for the project.
- In your local repo, build the site:
npm run build. Verify the output folder exists and contains HTML files, usuallydist/index.htmlfor Astro / Vite orbuild/index.htmlfor some other tools. - Install and sign in to the Firebase CLI:
npm install -g firebase-tools, thenfirebase login. If you manage multiple Google accounts, runfirebase login:listafterward and confirm the right account is active. - Connect this repo to the Firebase project: run
firebase init hosting, choose “Use an existing project”, select the project you just created, set the public directory to your build output (dist,build, orout), and choose “No” for GitHub deploys unless you want CI now. - Answer the SPA question carefully: choose “No” for Astro / Hugo / multi-page static sites; choose “Yes” only for a client-side router app where every route should serve
/index.html. - Check the generated files.
.firebasercshould contain your Firebase project ID, andfirebase.jsonshould pointhosting.publicat the build folder you verified. - Add production-safe Hosting settings in
firebase.json: usecleanUrls: truefor extensionless URLs, keep HTML cache short (no-cacheor a few minutes), and give hashed assets a long cache (Cache-Control: public,max-age=31536000,immutable). - Preview locally with Firebase, not just your framework dev server: run
firebase emulators:start --only hostingorfirebase serve --only hosting, then test/, an article page,/404,/sitemap.xml, and/robots.txt. - Deploy: run
npm run buildagain, thenfirebase deploy --only hosting. Open the printedhttps://<project-id>.web.appURL and click through the same pages you tested locally. - If the
*.web.appsite is correct, add your custom domain in Firebase console > Hosting > Add custom domain. Add the TXT verification record first, then add the A or CNAME records Firebase gives you. - Wait for DNS and SSL. Most domains connect within minutes, but give it a few hours before changing unrelated settings. Test both apex and www, plus
http://tohttps://redirect behavior. - Finish the launch: update canonical URLs and sitemap base URL, submit the sitemap in Google Search Console, and save a note with the project ID, deploy command, public directory, and DNS records.
Reference firebase.json
A production-safe config for an Astro / Vite / Hugo static site:
{
"hosting": {
"public": "dist",
"cleanUrls": true,
"trailingSlash": false,
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"headers": [
{
"source": "**/*.@(js|css|woff2|svg|webp|png|jpg)",
"headers": [{ "key": "Cache-Control", "value": "public,max-age=31536000,immutable" }]
},
{
"source": "**/*.html",
"headers": [{ "key": "Cache-Control", "value": "no-cache" }]
}
]
}
}
Common CLI commands you will use repeatedly:
npm run build # produce dist/
firebase emulators:start --only hosting # local preview at :5000
firebase deploy --only hosting # push live
firebase hosting:channel:deploy preview --expires 7d # share a preview link
firebase hosting:sites:list # confirm which site got the deploy
After-launch verification
- Open the
*.web.appURL and the custom domain in an incognito window; test homepage, deep article URL, 404, sitemap, robots, and mobile layout. - Run
firebase hosting:sites:listand confirm you deployed to the intended project, especially if you have multiple Firebase projects. - In the Firebase console, check Hosting > Release history and confirm the latest release time matches your deploy.
- Use Search Console URL Inspection after DNS settles to confirm Google can fetch the page and sees the canonical URL you expect.
Common pitfalls
- Skipping Firebase project creation and trying to run
firebase initagainst an account with no project selected. - Choosing the wrong Google account in the CLI, then deploying to a personal test project instead of the production project.
- Setting public to the source folder instead of the build output — your site will be live but blank.
- Choosing “configure as a single-page app” by accident, which rewrites every URL to
/index.htmland breaks SEO for multi-page sites. - Forgetting to set
no-cacheon HTML — visitors keep seeing the old page after each deploy. - Skipping the DNS verification step and getting stuck on “needs setup” for hours.
- Deploying from a dirty working tree without checking what files Firebase will upload.
Who this is for
Anyone shipping a static site (Astro, Vite, Hugo, plain HTML) who wants HTTPS, a CDN, and a custom domain on the free tier.
When to skip this
Apps that need full server-side rendering on every request, real-time websockets, or region-pinned routing — those belong on a framework-native host.
FAQ
- Do I need to pay anything to deploy?: No. Spark (free) tier covers the deploy, the
*.web.appURL, custom domain, and SSL. - How long until my custom domain works?: Usually 15 minutes to a few hours after the DNS records are set. SSL provisioning happens in parallel.
- Can I roll back a bad deploy?: Yes. In Firebase console, Hosting > Release history > pick a previous release > Rollback. It is one click.
- Where do I put environment variables?: Static sites bake env vars at build time. Put them in your build pipeline, not in
firebase.json. - What about preview branches?: Use
firebase hosting:channel:deploy <name>to get a temporary preview URL with auto-expiry.
Related
- What is Firebase Hosting
- Connecting a custom domain to Firebase Hosting
- Firebase Hosting go-live checklist
- Firebase Hosting Headers Config: Cache, Security, CORS
Tags: #Indie dev #Firebase #Hosting #Getting started #Workflow