Complete the steps listed on the Hosting Get Started page, which include installing the Firebase CLI and connecting your local project to your Firebase project.
Serve and test your Firebase project locally (optional)
You can view and test your Firebase project on locally hosted URLs before
deploying to production. If you only want to test select features, you can use
a comma-separated list in a flag on the
firebase serve command.
Run the following command from the root of your local project directory if you want to either:
- View the static content for your Firebase-hosted app.
- Use Cloud Functions to generate dynamic content for Firebase Hosting and you want to use your production (deployed) HTTP functions to emulate Hosting on a local URL.
firebase serve --only hosting
Run any of the following commands from your project directory to emulate your project using local HTTP functions.
To emulate HTTP functions and hosting for testing on local URLs, use either of the following commands:
firebase serve --only functions,hosting // uses a flag
To emulate HTTP functions only, use the following command:
firebase serve --only functions
Deploy to your site
To deploy to your site, run the following command from the root of your local project directory:
This command deploys a release to your Firebase project's default
and to any custom domains that you've connected
to your Hosting site.
You can optionally add a comment to a deploy. This comment will display with the other deployment information on your project's Hosting page. For example:
firebase deploy -m "Deploying the best new feature ever."
Deploys for projects with multiple sites
If you've added additional sites to your Firebase project, use the following command to deploy to one of those sites:
firebase deploy --only hosting:target-name
The target-name parameter is the unique identifier that you specified for the additional Hosting site during its setup.
Add predeploy and postdeploy scripted tasks
You can optionally connect shell scripts to the
firebase deploy command to
perform predeploy or postdeploy tasks. For example, a postdeploy hook could
notify administrators of new site content deploys. Refer to the
Firebase CLI documentation for
Caching deployed content
When a request is made for static content, Firebase Hosting automatically caches the content on the CDN. If you redeploy your site's content, Firebase automatically clears all your cached static content across the CDN so that new requests receive your new content.
Note that you can configure the caching of dynamic content.
Serving over HTTPS
As you're developing your application, make sure that all external resources that are not hosted on Firebase Hosting are loaded over SSL (HTTPS), including any external scripts. Most browsers do not allow users to load "mixed content" (SSL and non-SSL traffic).
Manage deploys and versions
To rollback to a previous deploy, hover over its entry in the list, click the three-dot overflow menu icon, then click Rollback.
Set limit for retained versions
Using a setting in the Firebase console, you can control how many of your site's past deployed versions are retained. The content of any versions over your set limit are scheduled for deletion, starting with the oldest versions first.
This setting can be helpful to control the level of storage maintained for your site. You can monitor your Hosting storage from your project's Hosting page, via Usage > Storage.
To set the limit for retained versions:
In the Release History pane for your site, click the three-dot overflow menu for the table, then select Version history settings.
Enter the number of versions that you'd like to retain, then click Save.