Jika Anda membangun aplikasi Angular atau Next.js yang dirender server, lihat Firebase App Hosting generasi berikutnya, sebuah solusi full stack untuk framework web modern.
Menayangkan konten dinamis dan menghosting microservice menggunakan Firebase Hosting
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Firebase Hosting terintegrasi dengan opsi komputasi serverless, termasuk Cloud Functions for Firebase dan Cloud Run. Dengan menggunakan Firebase Hosting bersama kedua opsi ini, Anda dapat menghosting microservice dengan mengarahkan permintaan HTTPS untuk memicu fungsi dan aplikasi dalam container agar berjalan dalam lingkungan yang aman dan terkelola.
Cloud Functions for Firebase: Anda menulis dan men-deploy fungsi, yaitu kode backend yang merespons pemicu tertentu. Selanjutnya, dengan menggunakan Firebase Hosting, Anda dapat mengarahkan permintaan HTTPS untuk memicu fungsi agar berjalan.
Cloud Run: Anda menulis dan men-deploy aplikasi yang dikemas dalam image container. Selanjutnya, dengan menggunakan Firebase Hosting, Anda dapat mengarahkan permintaan HTTPS untuk memicu aplikasi dalam container agar berjalan.
Kasus penggunaan
Bagaimana cara menggunakan opsi komputasi serverless dengan Firebase Hosting?
Menayangkan konten dinamis — Selain menayangkan konten statis di situs Hosting, Anda dapat menayangkan respons yang dibuat secara dinamis dari sebuah fungsi atau aplikasi dalam container yang menjalankan logika sisi server.
Misalnya, Anda dapat mengarahkan pola URL (seperti /blog/<blog-post-id>) ke sebuah fungsi yang menggunakan parameter ID postingan blog URL tersebut untuk mengambil konten secara dinamis dari database Anda.
Mem-build REST API — Anda dapat membuat API microservice menggunakan fungsi.
Misalnya, fungsi dapat menangani fungsionalitas login untuk situs Anda. Situs Anda dihosting di /, namun semua permintaan ke /api akan dialihkan ke API microservice Anda. Sebagai contoh, lihat contoh open source ini.
Menyimpan konten dinamis di cache — Anda dapat mengonfigurasi caching untuk konten dinamis Anda pada CDN global.
Misalnya, jika sebuah fungsi hanya menghasilkan konten baru secara berkala, Anda dapat mempercepat aplikasi dengan menyimpan konten yang dihasilkan di cache selama setidaknya periode waktu yang singkat. Anda juga berpotensi dapat mengurangi biaya eksekusi karena konten disalurkan dari CDN, bukan melalui aplikasi dalam container atau fungsi yang dipicu.
Melakukan render awal untuk aplikasi satu halaman — Anda dapat meningkatkan SEO dan mengoptimalkan berbagi di berbagai jaringan sosial dengan membuat tag meta dinamis. Untuk mempelajari lebih lanjut, tonton video ini atau lihat contoh open source ini.
Memilih opsi tanpa server
Meskipun Cloud Functions for Firebase dan
Cloud Run terintegrasi dengan
Firebase Hosting dan menawarkan lingkungan serverless yang terkelola sepenuhnya, bisa melakukan penskalaan otomatis, dan aman, kedua opsi tersebut dapat dimanfaatkan untuk berbagai kasus penggunaan dan tingkat konfigurasi kustom yang diinginkan.
Saat menggunakan salah satu opsi serverless, sebaiknya lakukan kolokasi dengan server untuk Firebase Hosting dengan men-deploy di salah satu region berikut:
us-west1
us-central1
us-east1
europe-west1
asia-east1
Tabel berikut menjelaskan beberapa pertimbangan dasar terkait penggunaan Cloud Functions for Firebase versus Cloud Run. Untuk mengetahui daftar lengkap kuota, batas, dan metrik, lihat dokumentasi mendetail setiap produk (Cloud Functions for Firebase atau Cloud Run).
Pertimbangan
Cloud Functions for Firebase
Cloud Run
Penyiapan
Firebase CLI memaketkan beberapa tugas menjadi satu perintah, dari inisialisasi hingga mem-build dan men-deploy project.
Container menawarkan lebih banyak opsi yang dapat disesuaikan, sehingga tugas penyiapan, build, dan deployment membutuhkan langkah-langkah tersendiri.
Lingkungan runtime
Memerlukan Node.js, tetapi Anda dapat menentukan versi Node.js yang akan digunakan.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-14 UTC."],[],[],null,["\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nFirebase Hosting integrates with serverless computing options, including\nCloud Functions for Firebase and Cloud Run. Using Firebase Hosting with\nthese options, you can host microservices by directing HTTPS requests to trigger\nyour functions and containerized apps to run in a managed, secure environment.\n\n[**Cloud Functions for Firebase**](/docs/hosting/functions): You write and deploy a\nfunction, which is backend code that responds to a specific trigger. Then, using\nFirebase Hosting, you can direct HTTPS requests to trigger your function\nto run.\n\n[**Cloud Run**](/docs/hosting/cloud-run): You write and deploy an\napplication packaged in a container image. Then, using Firebase Hosting, you\ncan direct HTTPS requests to trigger your containerized app to run.\n| **Note:** If you're using Angular or Next.js to develop a full-stack Web app with server-side rendering or AI features, try out the preview of [App Hosting](/docs/app-hosting). App Hosting is a unified product for managing static and dynamic content together.\n\nUse cases\n\nHow can you use serverless computing options with Firebase Hosting?\n\n- **Serve dynamic content** --- In addition to serving static content on\n your Hosting site, you can serve dynamically generated responses from a\n function or containerized app that is performing server-side logic.\n\n For example, you can point a URL pattern (like `/blog/\u003cblog-post-id\u003e`) to a\n function that uses the URL's blog post ID parameter to retrieve content\n dynamically from your database.\n- **Build REST APIs** --- You can create a microservice API using functions.\n\n For instance, functions can handle the sign-in functionality for your\n website. While your website is hosted at `/`, any request to `/api` is\n redirected to your microservice API. For an example, check out\n [this open-source sample](//github.com/firebase/functions-samples/tree/Node-8/authenticated-json-api).\n- **Cache dynamic content** --- You can\n [configure caching](/docs/hosting/manage-cache) of your dynamic content on\n a global CDN.\n\n For example, if a function generates new content only periodically, you\n can speed up your app by caching the generated content for at least a short\n period of time. You can also potentially reduce execution costs because the\n content is served from the CDN rather than via a triggered function or\n containerized app.\n- **Prerender your single-page apps** --- You can improve SEO and optimize\n sharing across various social networks by creating dynamic `meta` tags. To\n learn more, watch this [video](//www.youtube.com/watch?v=82tZAPMHfT4)\n or check out\n [this open-source sample](//github.com/firebase/functions-samples/tree/Node-8/isomorphic-react-app).\n\nChoosing a serverless option\n\nWhile both [**Cloud Functions for Firebase**](/docs/hosting/functions) and\n[**Cloud Run**](/docs/hosting/cloud-run) integrate with\nFirebase Hosting and offer a fully managed, autoscaling, and secure\nserverless environment, the two options can be leveraged for different use cases\nand desired level of customized configuration.\n\nWhen using either serverless option, it is best to co-locate it with the servers\nfor Firebase Hosting by deploying in one of the following regions:\n\n- `us-west1`\n- `us-central1`\n- `us-east1`\n- `europe-west1`\n- `asia-east1`\n\nThe following table describes some basic considerations for using\nCloud Functions for Firebase versus Cloud Run. For a full listing of\nquotas, limits, and metrics, refer to each product's detailed documentation\n([Cloud Functions for Firebase](/docs/functions/quotas) or\n[Cloud Run](//cloud.google.com/run/quotas)).\n\n| **Consideration** | **Cloud Functions for Firebase** | **Cloud Run** |\n|-------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **Setup** | The Firebase CLI bundles multiple tasks into single commands, from initializing to building and deploying. | Containers offer more customizable options, so setup, build, and deployment tasks involve discrete steps. |\n| **Runtime environment** | Requires Node.js, but you can specify [which version](/docs/functions/manage-functions#set_runtime_options) of Node.js to use. | When [building your container](/docs/hosting/cloud-run#containerize), you specify the runtime environment. |\n| **Language and frameworks support** | JavaScript and TypeScript Web frameworks, like Express.js, are supported. | Any language that Dockerfiles support, including [Go, Node.js, Python, Java, and others](//cloud.google.com/run/docs/quickstarts/build-and-deploy#writing) Web frameworks for each language are supported. |\n| **Timeout for Hosting request** | 60 seconds (see Note below) | 60 seconds (see Note below) |\n| **Concurrency** | 1 request per function instance (no concurrency per instance) | Up to 1,000 concurrent requests per container instance |\n| **Billing** | [Cloud Functions usage](/pricing) Free usage quota, but a [Cloud Billing account](//cloud.google.com/billing/docs/how-to/manage-billing-account) is required. See the [Firebase FAQ](/support/faq#functions-pricing). | [Cloud Run usage](//cloud.google.com/run/pricing) + [Container Registry storage](//cloud.google.com/container-registry/) Free usage quota, but a [Cloud Billing account](//cloud.google.com/billing/docs/how-to/manage-billing-account) is required |\n| **Billing** | | If your Firebase project is on the Spark pricing plan, and you associate your Firebase project with a Cloud Billing account, then your Firebase project is automatically upgraded to the Blaze pricing plan. Review the [Firebase pricing page](/pricing) for a comparison of the Spark and Blaze plans. ||\n\n| **Note:** Even though Cloud Functions and Cloud Run have longer request timeouts, Firebase Hosting is subject to a 60-second request timeout. If your app requires more than 60 seconds to run, you'll receive an HTTPS status code `504` (request timeout)."]]