简体   繁体   English

setInterval 多次加载文件

[英]setInterval load file multiple times

I have a setInterval function in my code, that loads a json file every 1 minute and this update the data in my page.我的代码中有一个 setInterval 函数,它每 1 分钟加载一个 json 文件,这会更新我页面中的数据。

I can see it in Chrome DevTools/Network, look like this:我可以在 Chrome DevTools/Network 中看到它,如下所示:

file.json?123

After a minute something like this:一分钟后是这样的:

file.json?1234

My question is, if it is loading the file every time or just replacing the file.我的问题是,它是每次都加载文件还是只是替换文件。

In Chrome DevTools/Network at bottom appears:在 Chrome DevTools/Network 底部出现:

10 MB Transferred |已传输 10 MB | 15 MB Resource 15 MB 资源

This is increasing every time load the file again.每次再次加载文件时,这都会增加。

can this overload the page and make crash it?这可以重载页面并使其崩溃吗?

since you are replacing the old file by the new, your old files will be removed from your computer's memory.由于您正在用新文件替换旧文件,因此旧文件将从计算机内存中删除。 Make sure you are not keeping any reference to your old files in your code to be sure.确保您没有在代码中保留对旧文件的任何引用。

From what I understand your files are different every time, file.json?123 is different from file.json?1234 .据我了解,您的文件每次都不同, file.json?123file.json?1234不同。 This means that these are downloaded resources, so it's fine to see a bigger value for Transferred and Resource .这意味着这些是下载的资源,因此可以看到TransferredResource的更大值。

You can check a similiar behaviour in an infinit scrolling page (like Facebook), where you make new request while scrolling down, so you will have new content, which means more resources and transferred data.您可以在无限滚动页面(如 Facebook)中检查类似行为,您在向下滚动时发出新请求,因此您将拥有新内容,这意味着更多资源和传输的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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