I have an API JSON.
this API changes very often:
it can change 10 times in a minute
or also 1 time an hour
or also 1 time a month.
all things depend on the parameters passed, a few parameters passed are more likely will change.
the problem is I don't know how many times, and I don't want to fetch every millisecond.
so is there any way to fetch it like it is a event listener?
like something like this:
window.addEventListener("APIchange", () => {
console.log("api changed");
});
so what do I want?
fetch data at the start of the app
wait for changes
if is changes don't fetch (don't consume data)
- BUT add a button with data changed N times
and if someone clicks the button then fetch the data (so we don't waste internet if user don't want new data, but I want to show to him that it changed N times)
literally something like question on stackoverflow.
here an example of API if you want to: https://api.stackexchange.com/2.3/questions?page=1&pagesize=10&fromdate=1666915200&todate=1667001600&order=desc&sort=activity&tagged=javascript&site=stackoverflow (is the same of StackOverflow, mine is different but is like it)
yes, there is some similar answers here: How to check if JSON is changed in Javascript? but they need everytime to fetch entire data even if not needed. I only need to add the count, create the button and increment the count, on click then fetch, button disappear