Skip to content
Permalink
Fetching contributors…
Cannot retrieve contributors at this time
153 lines (129 sloc) 4.77 KB
title lastmod publishdate author draft description tags youtube
Top 100 Firebase Tips and Tricks
2019-10-09 20:31:24 -0700
2019-10-09 20:31:24 -0700
Jeff Delaney
false
A collection of tips, tricks, and common mistakes you should know about when working with Firebase.
firebase
iWEgpdVSZyg

The list below outlines the Firebase tips presented in the video.

Get Started

  1. Create a two Firebase Projects - one for development and another for live production data
  2. Link Google Analytics
  3. Limit permissions for employees, follow the Principle of Least Privilege
  4. Update contact info for GDPR
  5. Add a project and don't worry about exposing your credentials in frontend code
  6. Upgrade to Blaze, then set a budget on GCP
  7. Generate detailed reports for billing
  8. Install the Firebase Tools CLI and GCloud. You should be able to run firebase and gcloud from the command line.

Hosting and Distribution

  1. Use App Distribution to bypass Google Play and Apple Test Flight
  2. Use NPM Scripts to build/deploy your app
  3. Use --project flag to avoid deploying to the wrong project
  4. Use the the cool new web.app domain
  5. Add additional sites with multisite hosting
  6. Rewrite routes to Cloud Function or Cloud Run
  7. Rewrite routes Dynamic Links
  8. Set custom CORS Headers
  9. Set custom Cache Headers
  10. Add CI/CD with Cloud Build

Frontend Setup

  1. RTDB vs Firebase
  2. Stop worrying about pricing
  3. Backup your Firestore data
  4. Start the Database in locked mode
  5. Run queries from the console
  6. Know the right JS import syntax
  7. Import services from firebase/app
  8. Defer script tags that contain the Firebase SDK.
  9. Angular App? Use AngularFire
  10. React App? Use ReactFire
  11. RxJS? Use RxFire
  12. Find additional projects from the FirebaseExtended Github Org.
  13. Use Performance Monitoring
  14. Use Crashlytics
  15. Use Analytics

Auth + Firestore Techniques

  1. Get the current user as a Promise OR add a realtime listener.
  2. Learn async programming
  3. Handle auth errors
  4. Implement lazy auth by linking auth methods
  5. Create your own custom email action handlers
  6. One-To-One relationships with a DocID
  7. Use the merge: true for a non-destructive Firestore set
  8. OneToMany relationships with a sub-collection
  9. Query collections with a common name using collectionGroup
  10. Many-To-Many with a UID Map
  11. Use duplication to increase performance and reduce costs
  12. Query Map values with dot notation
  13. Query data once OR with a realtime listener
  14. Listen to specific doc changes
  15. Sync browser tabs for offline persistence
  16. Use emojis in your code
  17. Wildcard string queries with ~
  18. Create indicies by viewing the Firestore error logs
  19. Write to lists with array union & remove
  20. Query lists with array-contains
  21. Pipeline concurrent single doc read requests
  22. Use serverTimestamp to update times
  23. Use increment to update counters
  24. Use the Distributed Counter extension
  25. Run atomic writes with batch
  26. Don't be afraid to integrate an SQL or Fulltext Search database

Rules

  1. Always use rules
  2. Play with the Simulator
  3. Test with the Emulator
  4. Make your rules fine-grained based on read/write types
  5. request vs resource
  6. Use get to read other database locations
  7. Simplify rules with functions

Storage

  1. Create multiple buckets, use coldline for infrequently accessed data.
  2. Save the download URL and file location to Firestore
  3. Make a references with refFromURL
  4. List all files in a directory
  5. Calculate progress with bytesTransferred / totalBytes
  6. Upload concurrently
  7. Assign metadata
  8. Use the Resizer extension

Admin

  1. Create a Admin script for Node.js
  2. Keep your Service Account private via gitignore or an environment variable
  3. Seed the Database with Faker.js
  4. Use the REST APIs
  5. Integrate googleapis for better REST code.

Cloud Functions

  1. Use TypeScript
  2. Minimize dependencies
  3. Use Global Variables
  4. Write idempotent code
  5. Adjust runWith Settings for more time and memory
  6. Avoid infinite loops
  7. Use isEqual to break infinite loops
  8. Always return a Promise
  9. Use PubSub functions for internal services
  10. Use callable functions for user auth
  11. Delete Firestore collections in batches
  12. Write small, pure JS functions
  13. Use Third-Party APIs
  14. Deploy single functions
  15. Test functions in the shell
  16. Customize logging with Stackdriver

Analytics

  1. Record events and user properties
  2. Create audiences
  3. Customize the UX with remote config
  4. Send smart notifications
  5. Sprinkle in some Machine Learning

And don't forget to have fun!

You can’t perform that action at this time.