0
votes

I am running a next.js application for serverside rendering on google cloud functions through firebase hosting rewrites. Together with caching, this works extremely well. However, when the cache is expired or a certain route is not yet cached one may encounter quite a bit of latency due to a function cold start since the function has not been invoked for a certain time. I am wondering if there is any elegant way to serve a loading view (e.g. a simple .html file) during the function boot-up so the user doesn't have the feeling that his connection is down or the page is not loading.

Any suggestions are welcome.

1

1 Answers

2
votes

I'm having the same problem experiencing latencies ~30s...

I'm tackling it with 3 ways.

  • I pre-render pages that don't require user data and deploy them with firebase hosting.
  • I use service workers to cache data in the device space while I'm making requests to functions to warm them get the response and cache it again...
  • For some pages I have a cron job where I keep the specific function alive which for me is a hack...