I am trying to fetch data from my server as often as possible.
To do so, I use the fetch method inside an AnimationFrame.
However, this work pretty well the first 30 secondes, and then it began to lag. When I looked at the Inspector, I can see that at every fetch I perform, the data the browser received is saved in a Fetches folder... resulting in thousands of files.
How can I delete the data stored in the Fetches folder?
Here the main code:
function fetch_from_server() {
if (has_new_value) {
let infos = new FormData();
infos.append('x', player.x);
infos.append('y', player.y);
infos.append('csrfmiddlewaretoken', csrf.getAttribute('value'));
return fetch(url_info, {
method: 'POST',
body: infos,
credentials: 'same-origin',
})
.then(response => response.json())
.then(json => {
update_p(json);
})
.then(_ => {
has_new_value = false;
is_fetching = false;})
.catch(error => console.log('Error:', error));
}
else {
return fetch(url_info)
.then(response => response.json())
.then(json => {
update_p(json);
})
.then(is_fetching = false)
.catch(error => console.log('Error:', error));
};
};
// Update Loop
function update(timestamp) {
if (!is_fetching) {
delay = (timestamp - last_update_time); // milliseconds
is_fetching = true
my_fetch = fetch_from_server();
}
rAF = window.requestAnimationFrame(update);
};
I requested the first AnimationFrame with a click Event Listener. This is just a simple project to exchange data between browser in a mini-game. I just wanted to play with javascript but I am stuck here and I found the answer to my problem nowhere.
Thank you all!
AdrKacz
PS: Even if I often use StackOverflow, this is my first post, I apologise if I did not respect some standard.