Hey, thanks for the info; could you put up code examples for how that works?
Philipp Rottner
1

I don’t render my Firebase data on the server, just the client. However soon I’ll be doing a post on fast, safe server-side rendering of async data. The idea is:

  • When the server starts, hit your api (the npm version of Firebase is the same as the client version) and store it in memory and in a JSON file.
  • Use setInterval to hit the api and update the cache every x seconds.
  • When a network request comes in, get the content synchronously from memory.
  • If it’s not in memory yet, get it from the file and also store it in memory for the next request.
  • If the API is completely down you’ll always have the json file.
  • If you’re rendering a lot of React on the server, time it, it might be taking a few hundred milliseconds of CPU, in which case you should cache your HTML responses (there’s express libs for this or write your own).
  • If you’re using a CDN and caching the whole HTML file then performance isn’t really an issue and you can just hit firebase directly since your web server won’t get much traffic.
Like what you read? Give David Gilbertson a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.