Tips for hosting static sites with Firebase App Hosting

Jeff Huleatt

portrait of Jeff Huleatt

It’s possible to deploy static web apps to Firebase App Hosting with a few extra steps. App Hosting gives you a Cloud Run service behind Cloud CDN. You can change some App Hosting settings to reduce cost and make the most of Cloud CDN for static sites.

Reduce maxInstances in apphosting.yaml

By default, App Hosting will scale your underlying Cloud Run service up to 100 instances. This is likely overkill for a static site, so it’s worth setting maxInstances much lower, even to 1. Here’s how to do that:

  1. If you don’t have an apphosting.yaml file, create one with firebase init apphosting.

  2. Change maxInstances to 1 in the file.

    maxInstances: 1

Set cache headers

Most frameworks will set the correct cache headers for static assets, but it’s worth double checking the App Hosting caching docs to ensure you’re setting cache headers in a way that App Hosting/Cloud CDN understands.

The cache is cleared on each rollout, so you can set the longest cache times that Cloud CDN will allow.

Double check

The Usage tab of the App Hosting console has a few charts that are useful to see if these changes worked. “Cloud CDN - Outgoing Bandwidth” shows cached vs uncached requests by bandwidth, and “Cloud CDN - Request Count” shows cached vs uncached requests by count.

You can also check the “Cloud Run CPU Utilization” chart to see if you need to raise maxInstances above 1. If your CPU utilization is uncomfortably high, it’s probably worth raising maxInstances. This chart shows each rollout, so you can tell if a config change to apphosting.yaml has reduced CPU utilization.