How to Host Website on Firebase
How to Host Website on Firebase Firebase Hosting is a fast, secure, and scalable web hosting service provided by Google as part of the Firebase platform. Designed specifically for modern web applications—whether static sites, single-page apps (SPAs), or serverless-powered sites—it offers global content delivery, automatic SSL certificates, one-click deploys, and seamless integration with other Fir
How to Host Website on Firebase
Firebase Hosting is a fast, secure, and scalable web hosting service provided by Google as part of the Firebase platform. Designed specifically for modern web applicationswhether static sites, single-page apps (SPAs), or serverless-powered sitesit offers global content delivery, automatic SSL certificates, one-click deploys, and seamless integration with other Firebase services like Authentication, Firestore, and Cloud Functions. Hosting your website on Firebase eliminates the complexity of traditional server management, making it ideal for developers, startups, and even non-technical users who want to launch a professional website quickly and reliably.
The importance of choosing the right hosting platform cannot be overstated. A slow, insecure, or unreliable host can hurt user experience, SEO rankings, and conversion rates. Firebase Hosting addresses these concerns by leveraging Googles global infrastructure, ensuring sub-second load times from anywhere in the world. Additionally, its built-in HTTPS enforcement and automatic caching reduce bounce rates and improve search engine visibility. Unlike shared hosting providers that require manual configuration of domains, SSL, or CDNs, Firebase Hosting automates these processes, allowing you to focus on building your website rather than managing servers.
In this comprehensive guide, youll learn exactly how to host a website on Firebasefrom setting up your account to deploying your first live site. Well walk you through each step with clarity, provide best practices to optimize performance, recommend essential tools, showcase real-world examples, and answer common questions. By the end, youll have everything you need to confidently deploy your website on Firebase and take advantage of its powerful features.
Step-by-Step Guide
Prerequisites
Before you begin hosting your website on Firebase, ensure you have the following:
- A Google account (Gmail or Workspace)
- A website project (static HTML/CSS/JS files or a built frontend like React, Vue, or Angular)
- Node.js installed on your computer (required for Firebase CLI)
- A terminal or command-line interface (Terminal on macOS/Linux, Command Prompt or PowerShell on Windows)
If you dont have Node.js installed, download it from nodejs.org. Choose the LTS (Long-Term Support) version for maximum stability. Verify your installation by opening your terminal and typing:
node -v
npm -v
You should see version numbers returned (e.g., v20.10.0 and v10.2.3). If not, reinstall Node.js and restart your terminal.
Step 1: Create a Firebase Project
Start by navigating to the Firebase Console. If youre not already signed in, use your Google account to log in.
Once in the console, click Create a project. Youll be prompted to enter a project name. Use something descriptive, like my-portfolio-site or company-landing-page. Avoid special characters or spacesuse hyphens instead.
Disable Google Analytics for now unless you plan to track user behavior immediately. Click Create project. Firebase will initialize your project, which may take a few seconds.
After the project is created, youll land on the project overview dashboard. Look for the Hosting card and click Get started. If you dont see it, click Expand menu on the left sidebar and scroll to find Hosting.
Step 2: Install the Firebase CLI
The Firebase Command Line Interface (CLI) is the primary tool for deploying your website. Open your terminal and run the following command:
npm install -g firebase-tools
This installs the Firebase CLI globally on your system. To verify the installation, type:
firebase --version
You should see a version number like 12.8.0. If you get an error, ensure Node.js and npm are correctly installed and try running the command with sudo on macOS/Linux (e.g., sudo npm install -g firebase-tools).
Step 3: Authenticate Firebase CLI with Your Google Account
Next, link your local CLI to your Firebase account. In your terminal, run:
firebase login
This opens a browser window where youll be asked to sign in to your Google account. Select the same account you used to create the Firebase project. After successful authentication, youll see a confirmation message in your terminal: Login successful.
Step 4: Initialize Your Firebase Project Locally
Navigate to the root directory of your website project in the terminal. For example:
cd /path/to/your/website
If you dont have a website yet, create a simple one. Make a folder called my-website, and inside it, create an index.html file:
mkdir my-website
cd my-website
echo "<!DOCTYPE html><html><head><title>My Firebase Site</title></head><body><h1>Hello from Firebase!</h1></body></html>" > index.html
Now, initialize Firebase in this directory:
firebase init
Youll be prompted with a series of questions. Heres how to respond:
- Which Firebase features do you want to set up for this project? Use the spacebar to select Hosting, then press Enter.
- Select a default Firebase project for this directory: Choose Use an existing project, then select your project from the list. If you dont see it, type the project ID manually (you can find it in the Firebase Console URL:
https://console.firebase.google.com/project/[your-project-id]). - What do you want to use as your public directory? Enter
public(default) or the folder containing your website files (e.g.,distfor React,buildfor Vue). Press Enter. - Configure as a single-page app? Type Y if your site uses client-side routing (React Router, Vue Router, etc.). This ensures all routes redirect to
index.html. - File
public/index.htmlalready exists. Overwrite? Type N if you already have an index.html. Otherwise, type Y to let Firebase generate a default one.
Once completed, Firebase creates a firebase.json configuration file and a public folder (if it doesnt exist). The firebase.json file tells Firebase how to serve your site. Heres an example:
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"/node_modules/"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
Step 5: Add Your Website Files
Place all your website files (HTML, CSS, JavaScript, images, fonts) inside the public folder. If youre using a build tool like React, Vue, or Angular, first build your project:
- React:
npm run build? moves files tobuild/ - Vue:
npm run build? createsdist/ - Angular:
ng build? generatesdist/
Then, update the public field in firebase.json to point to the build folder:
"public": "dist"
Ensure your index.html file is in the root of the public folder. Firebase will serve this file as the homepage.
Step 6: Deploy Your Website
With your files in place and configuration set, deploy your site with a single command:
firebase deploy
Firebase will:
- Validate your project structure
- Upload all files in the public directory
- Configure CDN caching and SSL
- Provide a live URL
Upon successful deployment, youll see output like:
? Deploy complete!
Project Console: https://console.firebase.google.com/project/my-portfolio-site/overview
Hosting URL: https://my-portfolio-site.web.app
Visit the provided URL to see your live website. Its now accessible globally, secured with HTTPS, and served via Googles edge network.
Step 7: Connect a Custom Domain (Optional)
By default, Firebase assigns you a subdomain like your-project.web.app or your-project.firebaseapp.com. To use your own domain (e.g., www.yourcompany.com), follow these steps:
- In the Firebase Console, go to Hosting ? Add custom domain.
- Enter your domain name (e.g.,
www.yourcompany.com) and click Continue. - Firebase will generate DNS records (CNAME or A records) that you must add to your domain registrar (e.g., GoDaddy, Namecheap, Cloudflare).
- Copy the DNS records shown and paste them into your registrars DNS management panel.
- Wait 560 minutes for DNS propagation. Firebase will automatically detect the changes and issue an SSL certificate.
- Once verified, your custom domain will be live. You can also enforce HTTPS-only traffic from the Hosting dashboard.
Pro tip: Use a CNAME record for subdomains (like www) and A records for root domains (like yourcompany.com). Firebase provides exact values for each.
Best Practices
Optimize File Structure and Asset Delivery
Performance begins with clean organization. Avoid placing large, unoptimized images or videos directly in your public folder. Use modern formats like WebP for images and compress them with tools like Squoosh or ImageOptim. For CSS and JavaScript, minify files using build tools like Webpack, Vite, or esbuild. Firebase automatically compresses assets with Brotli and serves them via CDN, but smaller files mean faster load times.
Structure your public folder logically:
public/
??? index.html
??? assets/
? ??? images/
? ? ??? logo.webp
? ? ??? banner.webp
? ??? css/
? ? ??? styles.min.css
? ??? js/
? ??? main.min.js
??? favicon.ico
Configure Caching Rules
By default, Firebase caches static assets for 1 hour. For better performance, extend cache lifetimes for immutable files (like bundled JS/CSS). Add a headers section to your firebase.json:
{
"hosting": {
"public": "public",
"ignore": ["firebase.json", "/.*", "/node_modules/**"],
"headers": [
{
"source": "**/*.@(jpg|jpeg|gif|png|svg|webp|ico)",
"headers": [
{
"key": "Cache-Control",
"value": "public, max-age=31536000"
}
]
},
{
"source": "**/*.@(js|css)",
"headers": [
{
"key": "Cache-Control",
"value": "public, max-age=31536000"
}
]
},
{
"source": "index.html",
"headers": [
{
"key": "Cache-Control",
"value": "no-cache"
}
]
}
]
}
}
This ensures images and bundles are cached for a year (31,536,000 seconds), while index.html is always fetched fresh to avoid stale content during updates.
Use Firebase Hosting with a Framework
Firebase Hosting works seamlessly with modern frameworks. Heres how to adapt common setups:
- React: Run
npm run build, then set"public": "build"infirebase.json. Enable single-page app rewrites. - Vue: Use
npm run build, set"public": "dist", and enable SPA rewrites. - Angular: Run
ng build --prod, set"public": "dist/your-project-name". - Next.js: Export as static site using
next export, then deploy theout/folder. - SvelteKit: Use
adapter-staticand deploy thebuild/folder.
Always test your build locally with a static server before deploying:
npx serve -s build
Enable HTTPS and Security Headers
Firebase Hosting automatically enables HTTPS for all sites. However, enhance security by adding HTTP headers in firebase.json:
{
"hosting": {
"headers": [
{
"source": "**",
"headers": [
{
"key": "Strict-Transport-Security",
"value": "max-age=63072000; includeSubDomains; preload"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-Frame-Options",
"value": "DENY"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
},
{
"key": "Content-Security-Policy",
"value": "default-src 'self'; script-src 'self' https://www.google-analytics.com; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:;"
}
]
}
]
}
}
These headers protect against clickjacking, MIME-sniffing, XSS, and other common web vulnerabilities.
Version Control and CI/CD Integration
Always commit your firebase.json and source files to version control (e.g., Git), but exclude the public/ folder if its generated (e.g., React build). Instead, automate deployment using GitHub Actions:
Create .github/workflows/deploy.yml:
name: Deploy to Firebase
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- run: npm run build
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT }}'
projectId: my-portfolio-site
channelId: live
Store your Firebase service account key as a secret in GitHub Settings ? Secrets. This enables automatic deployment on every push to main.
Monitor Performance and Errors
Firebase Hosting integrates with Google Analytics and Firebase Performance Monitoring. Enable these in the Firebase Console to track load times, page views, and errors. Use the Hosting tab to view deployment history and rollback to previous versions if needed.
Tools and Resources
Essential Tools for Firebase Hosting
- Firebase CLI The core tool for initializing, deploying, and managing projects. Install via
npm install -g firebase-tools. - VS Code Recommended code editor with Firebase extensions for syntax highlighting and IntelliSense for
firebase.json. - Netlify CLI (Alternative) If you later want to compare hosting platforms, Netlify offers similar features but Firebase integrates better with Google services.
- Squoosh Web-based image optimizer to convert PNG/JPG to WebP without losing quality.
- Google PageSpeed Insights Test your deployed sites performance and get optimization suggestions.
- SSL Labs (SSL Test) Verify your SSL certificate configuration and security grade.
- Cloudflare (Optional Proxy) Use Cloudflare in front of Firebase for additional DDoS protection, caching rules, or analytics.
Documentation and Learning Resources
- Official Firebase Hosting Documentation Comprehensive guides, API references, and troubleshooting.
- Firebase CLI Reference All commands and flags explained.
- Fireship.io Short, high-quality video tutorials on Firebase, including hosting.
- Firebase YouTube Channel Official updates and deep dives.
- Stack Overflow (firebase-hosting tag) Community support for common issues.
Template Repositories
Start quickly with these open-source templates:
- Firebase Quickstart Web Minimal React/Vue/Angular templates with Firebase integration.
- Next.js Static Export Template Perfect for content-heavy sites.
- Clean React + Firebase Template Includes routing, auth, and hosting config.
Real Examples
Example 1: Personal Portfolio Site
A designer uses React to build a portfolio with a home page, project gallery, and contact form. They use Vite for fast builds and deploy to Firebase Hosting.
- Build command:
npm run build - Public folder:
dist/ - Custom domain:
www.janedoe.design - Performance: 98/100 on PageSpeed Insights
- SEO: Meta tags, structured data, and sitemap.xml included
After deployment, the site loads in under 1.2 seconds globally, even on mobile networks. The designer uses Firebase Analytics to track which projects get the most views and adjusts content accordingly.
Example 2: Nonprofit Landing Page
A small nonprofit needs a fast, secure landing page to collect donations. They use plain HTML/CSS/JS with a Formspree backend for form submissions.
- Files:
index.html,style.css,script.js,favicon.ico - Deployment:
firebase deploy - SSL: Automatic, no setup required
- Result: The site ranks on page 1 of Google for donate to [nonprofit name] within 3 weeks due to fast load speed and mobile optimization.
Example 3: E-commerce Product Page (Static)
An online store uses Firebase Hosting to serve a static product page for a single item. The page includes high-res WebP images, a Buy Now button linked to Stripe, and a countdown timer.
- Cache headers: Images cached for 1 year, JS/CSS for 30 days
- CDN: Served from 30+ Google edge locations
- Uptime: 99.99% over 12 months
- Cost: $0 (Firebase Hosting is free for most use cases)
By hosting statically, they avoid server costs and reduce attack surface. The page handles 50,000+ monthly visitors with zero downtime.
Example 4: Open-Source Documentation Site
A developer builds documentation for a JavaScript library using Docusaurus. They use GitHub Actions to auto-deploy every time a new version is tagged.
- Build tool: Docusaurus ? generates static site in
build/ - CI/CD: GitHub Actions deploys to Firebase on
releaseevent - Custom domain:
docs.mylib.dev - Benefits: Instant updates, zero maintenance, and global access
This setup has reduced support queries by 40% because users always access the latest docs.
FAQs
Is Firebase Hosting free?
Yes. Firebase Hosting offers a generous free tier: 10 GB storage, 360 MB/day bandwidth, and unlimited deployments. Most personal projects and small business sites stay well under these limits. Paid plans start at $25/month for higher bandwidth and custom domain SSL priority.
Can I host a backend with Firebase Hosting?
No. Firebase Hosting serves only static files. For backend logic (APIs, databases, authentication), use Firebase Cloud Functions, Firestore, or Auth. You can connect your frontend to these services via JavaScript SDKs.
Does Firebase Hosting support server-side rendering (SSR)?
Not natively. Firebase Hosting is designed for static sites. For SSR, use Firebase Cloud Functions with frameworks like Next.js or Nuxt.js, but youll need to deploy the server separately. For true SSR, consider Vercel or Netlify.
How fast is Firebase Hosting?
Extremely fast. Firebase uses Googles global CDN, so your site loads in under 500ms from most locations. PageSpeed Insights scores typically exceed 90/100 for optimized sites.
Can I use Firebase Hosting with WordPress?
No. WordPress requires a PHP server and database, which Firebase Hosting does not support. Use WordPress on shared hosting, VPS, or managed platforms like WP Engine. Firebase is for static sites only.
How do I rollback a deployment?
In the Firebase Console ? Hosting ? click the three dots next to a deployment ? select Rollback. This reverts your site to that version instantly.
Can I use Firebase Hosting for multiple websites?
Yes. Each Firebase project can host one site. To host multiple sites, create separate Firebase projects or use Firebases multiple hosting sites feature (available on Blaze plan). You can also use subdomains like blog.yourdomain.com and app.yourdomain.com within one project.
Do I need to pay for SSL certificates?
No. Firebase automatically provisions and renews free SSL certificates via Lets Encrypt. Your site is HTTPS-only by default.
What happens if I exceed my bandwidth limit?
Firebase will notify you and temporarily pause your site until the next billing cycle or until you upgrade to a paid plan. Theres no sudden downtimejust a grace period.
Can I host a PWA (Progressive Web App) on Firebase?
Yes. Firebase Hosting is ideal for PWAs. Include a manifest.json and service worker file in your public folder. Firebase serves them correctly, and you can enable offline functionality.
Conclusion
Hosting your website on Firebase is one of the most efficient, secure, and cost-effective ways to launch a modern web project. Whether youre building a personal portfolio, a startup landing page, or a documentation site, Firebase eliminates the complexity of traditional hosting while delivering enterprise-grade performance and reliability. With its global CDN, automatic SSL, seamless integration with Google services, and effortless deployment pipeline, Firebase empowers developers of all skill levels to ship websites faster than ever before.
This guide walked you through every stepfrom setting up your Firebase project and installing the CLI, to deploying with custom domains and optimizing for speed and security. Youve seen real-world examples that prove Firebase Hostings versatility, and you now understand best practices that ensure your site performs at its peak.
Remember: The key to success isnt just deployingits optimizing. Minify assets, configure caching, use modern formats, and automate deployments. With these habits, your Firebase-hosted site wont just go liveit will thrive.
Now that you know how to host a website on Firebase, the next step is simple: build something great, deploy it, and share it with the world. Your audience is waiting.