Reserved URLs

Firebase Hosting reserves URLs in your site beginning with /__. This reserved namespace makes it easier to use other Firebase features together with Firebase Hosting. These reserved URLs are available when deployed as well as while running firebase serve locally.

Firebase SDK

Because Firebase Hosting is served over HTTP/2 when deployed, you can boost performance by loading files from the same origin. Firebase Hosting serves all versions of the Firebase JS SDK from special URLs formatted like so:

/__/firebase/{version}/{sdk-file}.js

We strongly recommend loading only the parts of the SDK you use. For example, if you are using Firebase Authentication and Cloud Storage together, you only need to include the following scripts:

<script src="/__/firebase/4.1.2/firebase-app.js"></script>
<script src="/__/firebase/4.1.2/firebase-auth.js"></script>
<script src="/__/firebase/4.1.2/firebase-storage.js"></script>

All versions of the Firebase SDK are hosted in this way and new versions become available as soon as they are released.

SDK Auto-Configuration

In addition to hosting the SDKs themselves, the reserved namespace also provides all of the configuration necessary to initialize the SDK for the project associated with the Firebase Hosting site. This is provided as a script that you can include directly:

<!-- load Firebase SDK before loading this file -->
<script src="/__/firebase/init.js"></script>

This script will automatically configure the Firebase SDK's default application. If you prefer to control initialization yourself, the configuration values are also available in JSON form:

fetch('/__/firebase/init.json').then(response => {
  firebase.initializeApp(response.json());
});

Automatic SDK configuration makes it easy to manage multiple environments (such as dev, staging, and production) from a single codebase. By relying on the reserved URL, you can deploy the same code to multiple Firebase projects.

Auth Helpers

Firebase Authentication uses the reserved namespace to provide special JavaScript and HTML to complete authentication with providers via OAuth. This allows each of our customers to have a unique domain for their project, increasing the security of Firebase Authentication.

In addition, this allows you to use your own custom domain for the authDomain option of firebase.initializeApp(). If you've configured a custom domain for Firebase Hosting, you can specify that custom domain instead of your firebaseapp.com subdomain when intializing the Firebase SDKs.

Reserved URLs and Service Workers

If you are building a Progressive Web App, you might create a service worker that has a "navigation fallback" and renders a specific URL by default if it doesn't match a list of precached items. You must disable the fallback for the /__ namespace for Firebase Hosting to function properly.

If you're using the sw-precache library, you can add a navigation fallback whitelist setting that excludes the reserved namespace:

{
  navigateFallbackWhitelist: [/^(?!\/__).*/]
}

In general, just remember that the double-underscore namespace is reserved for Firebase usage and you should not intercept these requests in your service worker.

Send feedback about...

Need help? Visit our support page.