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);
};
我通过单击事件监听器请求了第一个AnimationFrame。 这只是一个在迷你游戏中的浏览器之间交换数据的简单项目。我只是想玩JavaScript,但被困在这里,却无所适从。
谢谢你们!
阿德·卡茨
PS:即使我经常使用StackOverflow,这也是我的第一篇文章,如果我不遵守某些标准,我深表歉意。