Firebase Hosting: A Complete Guide
Firebase Hosting is a fast, secure, and reliable hosting service for web apps, static and
dynamic websites, and microservices. It provides a free SSL certificate, global CDN, and easy
deployment with just a few commands.
---
1. Key Features of Firebase Hosting
• Fast and Secure – Uses a global Content Delivery Network (CDN) for quick loading.
• Free SSL Certificate – Provides HTTPS automatically for security.
• Custom Domain Support – You can use your own domain (e.g., yourdomain.com).
• Supports Static & Dynamic Content – Can host HTML, CSS, JavaScript, and backend
services using Cloud Functions.
• Easy Deployment – Deploy with a single command using Firebase CLI.
---
2. Steps to Host a Website on Firebase
Step 1: Install Firebase CLI
Make sure you have Node.js installed. Then, install Firebase CLI globally:
npm install -g firebase-tools
Verify installation:
firebase --version
Step 2: Login to Firebase
Authenticate Firebase with your Google account:
firebase login
Step 3: Create a Firebase Project
1. Go to Firebase Console.
2. Click 'Add Project' and create a new project.
3. Enable Firebase Hosting in the setup options.
Step 4: Initialize Firebase in Your Project
Navigate to your project folder and run:
firebase init
Step 5: Deploy Your Website
Add your HTML, CSS, JavaScript files inside the 'public' folder.
Deploy the website with:
firebase deploy
3. Custom Domain Setup
To use a custom domain like 'www.yourwebsite.com':
• Go to Firebase Console → Hosting.
• Click 'Add custom domain'.
• Enter your domain name.
• Update DNS records in your domain provider (Firebase provides details).
• SSL is automatically applied.
4. Updating and Deleting a Site
To Update Your Website
Make changes in the 'public/' folder and redeploy:
firebase deploy
To Delete a Hosted Site
firebase hosting:disable
5. Firebase Hosting with a Backend
Firebase Hosting allows dynamic content using Cloud Functions for Firebase.
To enable Cloud Functions:
firebase init functions
Write your backend logic in 'functions/index.js' and deploy:
firebase deploy --only functions
6. Firebase Hosting Pricing
• Free (Spark Plan) – Includes 1GB storage & 10GB bandwidth per month.
• Pay as You Go (Blaze Plan) – Charges based on usage.
7. Alternatives to Firebase Hosting
• Netlify – Better for static sites with Git-based deployment.
• Vercel – Best for Next.js and React apps.
• GitHub Pages – Free for static websites.
Conclusion
Firebase Hosting is an excellent choice for fast and secure web hosting, especially for static
and dynamic web applications. It integrates well with Firebase services like Firestore,
Authentication, and Cloud Functions.