Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Firestore è una buona soluzione di database scalabile per mantenere i dati sincronizzati tra i client web.
Per molte app, il supporto offline gestito di Firestore è particolarmente importante, in quanto consente di creare app reattive che funzionano indipendentemente dalla latenza di rete o dalla connettività a internet. Tuttavia, gli SDK ricchi di funzionalità hanno un costo in termini di dimensioni. Cosa
offre Firebase per le app che devono utilizzare solo le operazioni di base di creazione, lettura, aggiornamento
ed eliminazione e non hanno bisogno del supporto offline gestito?
Soluzione: Firestore Lite
Firestore Lite è un SDK Firestore autonomo e leggero solo REST che
supporta recuperi di singoli documenti, esecuzione di query e aggiornamenti dei documenti, a
una frazione delle dimensioni dell'SDK web normale. Firestore Lite omette la compensazione della latenza,
la memorizzazione nella cache offline, la ripresa delle query e i listener di snapshot, ma per casi d'uso particolari, le riduzioni delle dimensioni della libreria e del tempo di avvio rappresentano un ottimo compromesso.
Importa Firestore Lite
Firestore Lite è disponibile tramite npm come parte dell'SDK modulare. È quindi
completamente modulare e tree-shakeable.
Per dimensioni e velocità, Firestore Lite omette queste funzionalità dall'SDK Firestore standard:
Gestori di eventi DocumentSnapshot. Il metodo onSnapshot e
gli oggetti DocumentChange, SnapshotListenerOptions, SnapshotMetadata,
SnapshotOptions e Unsubscribe non sono inclusi.
Helper di persistenza. I metodi enableIndexedDBPersistence,
enableMultiTabIndexedDbPersistence e clearIndexedDbPersistence
non sono inclusi.
Bundle Firestore. Il metodo loadBundle e i metodi correlati, nonché gli oggetti LoadBundleTask e LoadBundleTaskProgress non sono inclusi.
Implementare recuperi, query e aggiornamenti dei documenti
Dopo aver importato Firestore Lite, puoi effettuare tutte le chiamate API get
e update che conosci. Si applicano tutti i casi d'uso per l'aggiunta di dati e l'ottenimento di dati.
Può essere difficile decidere quando abbandonare le funzionalità di persistenza offline e memorizzazione nella cache dell'SDK Firestore standard. È consigliabile comprendere queste funzionalità
prima di decidere di rinunciarvi per il minor overhead di Firestore Lite. In
generale, valuta questi fattori quando decidi se utilizzare Firestore Lite:
Stato online: Firestore Lite è ideale per le app che non richiedono aggiornamenti
in tempo reale e hanno connettività.
Vincoli di dimensione: Firestore Lite è ideale se vuoi ridurre le dimensioni complessive del bundle JavaScript.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-06 UTC."],[],[],null,["\u003cbr /\u003e\n\nFirestore is a good scalable database solution to keep data in sync across Web\nclients.\n\nFor many apps, Firestore's managed offline support is especially important,\nletting you build responsive apps that work regardless of network latency or\nInternet connectivity. But feature-rich SDKs come at a size cost. What\ndoes Firebase offer for apps that only need to use basic create, read, update\nand delete operations, and don't need managed offline support?\n| **Note:** Before using Firestore Lite, be sure you understand the standard Firestore Web API and Firestore's offline capabilities as part of the full [feature set](../index.html). We recommend Firestore Lite for developers who have experience building with Firestore and can evaluate the tradeoffs of using a lightweight version.\n\nSolution: Firestore Lite\n\nFirestore Lite is a lightweight, standalone REST-only Firestore SDK that\nsupports single document fetches, query execution, and document updates, at a\nfraction of the regular Web SDK size. Firestore Lite omits latency compensation,\noffline caching, query resumption and snapshot listeners, but for particular\nuse cases, the reductions in library size and startup time make a great tradeoff.\n\nImport Firestore Lite\n\nFirestore Lite is available via npm as part of the\n[modular SDK](//firebase.google.com/docs/web/learn-more#modular-version). It is\nthus fully modular and tree-shakeable.\n\nThe following import style is supported. \n\n import { initializeApp } from \"firebase/app\";\n import {\n getFirestore,\n getDoc,\n updateDoc\n } from 'firebase/firestore/lite';\n\nAPI features not supported by Firestore Lite\n\nFor size and speed, Firestore Lite omits these features from the standard\nFirestore SDK:\n\n- **DocumentSnapshot event handlers** . The `onSnapshot` method and `DocumentChange`, `SnapshotListenerOptions`, `SnapshotMetadata`, `SnapshotOptions` and `Unsubscribe` objects are not included.\n- **Persistence helpers** . The `enableIndexedDBPersistence`, `enableMultiTabIndexedDbPersistence`, and `clearIndexedDbPersistence` methods are not included.\n- **Firestore bundles** . The `loadBundle` method and related methods, and the `LoadBundleTask` and `LoadBundleTaskProgress` objects are not included.\n\nImplement document fetches, queries and updates\n\nAfter importing Firestore Lite, you can make all of the familiar API get\nand update calls. The use cases for [adding data](../manage-data/add-data)\nand [getting data](../query-data/get-data) all apply. \n\n import {\n getFirestore,\n getDoc,\n updateDoc,\n doc\n } from '@firebase/firestore/lite';\n\n const firestore = getFirestore(app);\n const docRef = doc(firestore, 'collection/doc');\n const docSnap = await getDoc(docRef);\n await updateDoc(docRef, \"field\", 'value');\n\nWhen to use Firestore Lite\n\nIt can be tricky to decide when to let go of the standard Firestore SDK's\noffline persistence and caching features. You should understand these features\nbefore deciding to trade them away for the lower overhead of Firestore Lite. In\ngeneral, weigh these factors when deciding whether to use Firestore Lite:\n\n- **Online status** - Firestore Lite is good for apps that do not need live updates and have connectivity.\n- **Size constraints** - Firestore Lite is great if you want to reduce your overall JavaScript bundle size."]]