Simon Tran
Simon Tran

Reputation: 2100

What should I use to host a public JSON file that rarely changes without redeploying my whole webapp?

I've a react app hosted on firebase and a realtime database for user data.

Currently, there's a json file in my app's code containing reference data. This file might change once every few months.

Where could I host this file so that I could update it without redeploying the whole webapp?

I thought about using Firebase Storage, but it seems inefficient to download the file on every render. Is there a way to only download it once and cache it for a certain amount of time?

thank you

Upvotes: 0

Views: 46

Answers (1)

Parsa x86
Parsa x86

Reputation: 1109

yes, you can fetch it the first time and store it in localStorate, and about the expiration time, add a key as a specific expiration time, and when time over re-fetch it again, e.g (for three month later):

const date = new Date();
date.setMonth(date.getMonth() + 3);
const expirationTime = date.getTime();

{
   data: {...some data},
   expirationTime
}

and each time you have to check the expirationTime if the current time was bigger than expirationTime you have to re-fetch the data.

Upvotes: 1

Related Questions