gpt4 book ai didi

javascript - 为什么 history.js 使用 setInterval(.., 250)?

转载 作者:搜寻专家 更新时间:2023-11-01 04:42:04 24 4
gpt4 key购买 nike

据我了解History.jsHTML5 History/State APIs 的 polyfill .因此,在现代浏览器上,它应该简单地使用 popstate用于收听 URL 更改。那么,为什么在最新的 Chrome 上我可以看到计时器每 250 毫秒触发一次?这看起来很浪费,每隔几秒就会触发一次垃圾收集器。

看看这个官方History.js demo .

History.js demo page firing timer every 250ms

最佳答案

我不知道 History.js 代码,但通读它,我相信 @apsillers 是正确的。

它被配置为队列项之间的间隔为 250 毫秒。该队列中的一些排队函数需要获取历史状态。这些项目通过调用繁忙来强制冲洗暂停。

至于为什么这种情况也会发生在 HTML5 浏览器中,对我来说似乎是 History.JS 如果它是 HTML5 则不会只是切换一个开关然后什么都不做。在他们的 github它陈述了他们的目标之一:

Provide a cross-compatible experience for all HTML5 Browsers (they all implement the HTML5 History API a little bit differently causing different behaviours and sometimes bugs - History.js fixes this ensuring the experience is as expected / the same / great throughout the HTML5 browsers)

如果 History.js 仍在做一些涉及排队的工作,我猜他们会使用忙碌超时。

关于javascript - 为什么 history.js 使用 setInterval(.., 250)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17696953/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com