Fair question! So if you use a function like getStaticProps, you’re only calling the Contentful API when you first build the application. This means, after you’ve deployed your built website, the Contentful data exists as static JSON in your JavaScript bundle. So, whenever a user visits your site, they won’t make another call to Contentful to retrieve that data. So you could make 1 call and serve 100k users! You’ll only make future calls when you redeploy your site, which you can automatically trigger on content changes using a webhook
Thats awesome.
But my project its a little different. I think I can't redeploy my site everytime my data changes. I have a third party API that needs to be updated every 15seconds, but for this I dont need Contentful.
Where I need contentful Is on grab static data, for example I have a calendar that when I click on a day It grabs data from API related to the day that I selected, but for the past days the data will not change anymore, will be static so If I click on a day from last month I want to grab the info from contentful and not from third party api, but at same time I dont want my site to be reployed every 15s
Hm okay, so it sounds like you have 2 different data sources (3rd party API that changes often, Contentful data that doesn't change as often). So, to be clear, are you trying to funnel data from this API into Contentful when it becomes "static?" If so, I would recommend caching this data with Next's getServerSideProps and avoiding Contentful together. Lmk if I'm misunderstanding your comment though.
Exactly, I want to send the data to contentful when It doesnt change anymore. Im using Nuxt instead of next but It probably has a similar option. But you recommend caching data using getServerSideProps and not use contentful at all?
Right. That's mainly because Contentful is a CMS, so it's meant to be your content editor as well as your storage solution. In your case, it sounds like you'll never update these entries again once they've been saved, so you're probably just looking for a data storage solution. I haven't investigated server-side caching with Next, but it looks like they have an example you can clone right here. Your idea definitely isn't impossible! It was just be a lot of work to set up and maintain. You'd likely run into free tier limits as well, since you'll be writing a lot of entries at a time.
Exactly, I have to investigate more, Its a thing that I plan to do later in my project. Because the data will update every 15s but once the day is over that same data will not be updated ever again, and a new day starts with fresh data to be updated every 15s again. And I dont want to use headless CMS because If I have 10k online users and every single of them start to click on every day from last 5y, I'll reach the limit of calls.
Since Im using Vue 3, maybe I can create a db on server with the power of reactivity and once day is over I make a post to that db with the data , and if the user clicks on a day that is lesser than today will grab data from db, if not will grab data from third party api.
And maybe with service workers or with SS cache I can make it work. If only 1 user visits that page from 3y ago, 10k users will see instant on browser because Its already in cache.
Well this is what Im thinking dont know if will work or not
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Fair question! So if you use a function like getStaticProps, you’re only calling the Contentful API when you first build the application. This means, after you’ve deployed your built website, the Contentful data exists as static JSON in your JavaScript bundle. So, whenever a user visits your site, they won’t make another call to Contentful to retrieve that data. So you could make 1 call and serve 100k users! You’ll only make future calls when you redeploy your site, which you can automatically trigger on content changes using a webhook
Thats awesome.
But my project its a little different. I think I can't redeploy my site everytime my data changes. I have a third party API that needs to be updated every 15seconds, but for this I dont need Contentful.
Where I need contentful Is on grab static data, for example I have a calendar that when I click on a day It grabs data from API related to the day that I selected, but for the past days the data will not change anymore, will be static so If I click on a day from last month I want to grab the info from contentful and not from third party api, but at same time I dont want my site to be reployed every 15s
Hm okay, so it sounds like you have 2 different data sources (3rd party API that changes often, Contentful data that doesn't change as often). So, to be clear, are you trying to funnel data from this API into Contentful when it becomes "static?" If so, I would recommend caching this data with Next's
getServerSideProps
and avoiding Contentful together. Lmk if I'm misunderstanding your comment though.Exactly, I want to send the data to contentful when It doesnt change anymore. Im using Nuxt instead of next but It probably has a similar option. But you recommend caching data using getServerSideProps and not use contentful at all?
Right. That's mainly because Contentful is a CMS, so it's meant to be your content editor as well as your storage solution. In your case, it sounds like you'll never update these entries again once they've been saved, so you're probably just looking for a data storage solution. I haven't investigated server-side caching with Next, but it looks like they have an example you can clone right here. Your idea definitely isn't impossible! It was just be a lot of work to set up and maintain. You'd likely run into free tier limits as well, since you'll be writing a lot of entries at a time.
Exactly, I have to investigate more, Its a thing that I plan to do later in my project. Because the data will update every 15s but once the day is over that same data will not be updated ever again, and a new day starts with fresh data to be updated every 15s again. And I dont want to use headless CMS because If I have 10k online users and every single of them start to click on every day from last 5y, I'll reach the limit of calls.
Since Im using Vue 3, maybe I can create a db on server with the power of reactivity and once day is over I make a post to that db with the data , and if the user clicks on a day that is lesser than today will grab data from db, if not will grab data from third party api.
And maybe with service workers or with SS cache I can make it work. If only 1 user visits that page from 3y ago, 10k users will see instant on browser because Its already in cache.
Well this is what Im thinking dont know if will work or not