Firebase App Hosting gives you a Cloud Run service behind Cloud CDN. Since static sites don’t change, you can change some App Hosting settings to reduce cost and make the most of Cloud CDN.
Reduce maxInstances in apphosting.yaml
By default, App Hosting will scale your underlying Cloud Run service up to 100 instances. This is overkill for a static site, so it’s worth setting maxInstances much lower, even to 1. Here’s how to do that:
-
If you don’t have an
apphosting.yamlfile, create one withfirebase init apphosting. -
Change
maxInstancesto 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.