我可以检测浏览器的网络活动是否空闲吗? [英] Can I detect if a browser's network activity is idle?

查看:69
本文介绍了我可以检测浏览器的网络活动是否空闲吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在angularJS应用程序中,用户与服务器之间存在很大的延迟(带宽可能也会受到限制),因此,当用户请求新页面时,它必须等待大约2-500毫秒才能加载它.

In an angularJS app there is quite a big of latency between the user and the server (also bandwidth may be limited), so when the user requests a new page, it has to wait about 2-500ms for it to load.

我正在考虑在后台预加载"模型数据,模板,脚本,但仅在用户未请求页面的情况下才这样做.如果用户请求一个特定页面,我想停止预加载过程并加载用户明确请求的资源.

I'm thinking of "preloading" model data, templates, scripts in the background, but intend to do so ONLY if there is no page requested by the user. If the user requests one specific page I'd like to stop the preloading process and load the resources explicitly requested by the user.

所以我的问题归结为:

  • 是否有一种方法可以使ajax请求仅在没有网络活动的情况下"?
  • 有没有一种方法可以暂停"当前正在运行的ajax请求?或
  • 有没有办法确定ajax请求的优先级?

谢谢

推荐答案

好像 https://nicedoc.io/pastelsky/network-idle-callback 将为您提供帮助.

它使用serviceWorker观察网络呼叫,并在感知到网络空闲时调度事件.

It uses serviceWorker to observe network calls, and dispatch event when it senses network idle.

npm install network-idle-callback

用法

这篇关于我可以检测浏览器的网络活动是否空闲吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆