简体   繁体   中英

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

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, eg (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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM