JavaScript .hashchange性能。它会带来任何减速吗? [英] JavaScript .hashchange performance. Can it bring any slowdown?

查看:100
本文介绍了JavaScript .hashchange性能。它会带来任何减速吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery hashchange events

对我而言,它现在看起来是最成熟的解决方案(如果我错了,请纠正我)。
我真的很喜欢这个用浏览器哈希操纵的插件。在某些情况下,它会简化js代码。

For me it looks like most mature solution right now(please correct me if I'm wrong). I really like this plugin for manipulating with browsers hashes. It simplifies js code a lot in some cases.

我真的想开始大量使用它,但我有一个问题。

I really want to start use it extensively but I have a question for you.

相应于源它使用循环并检查散列锚是否每50毫秒更改一次。

Accordingly to the source it uses loop and check whether hash anchor was changed every 50 ms.

性能怎么样?我可以过度使用hashchange吗?它会导致性能显着下降吗?如果是这样的情况呢?

What about performance? Can I overuse hashchange? Can it lead to some significant slowdown in performance? If so in which cases?

推荐答案

每隔50ms检查一个简单的字符串属性是一个无穷小的成本,而不是所有否则你正在运行,我不会在这里关注性能。如果你经常改变哈希并且你的回调非常,非常那么处理那个(你回调),但是检查本身是一个非常非常的小成本。

Checking a simple string property every 50ms is an infinitesimal cost compared to probably everything else you're running, I wouldn't be concerned about performance here. If you're changing the hash often and your callback is very, very expensive then deal with that (you callback), but the check itself is a very, very small cost.

另请注意,50ms检查仅适用于没有 window.onhashchange 内置的浏览器在,对于那些它是一个本地事件(和那是最现代的浏览器)。

Also keep in mind that 50ms check is only for browsers that don't have window.onhashchange built-in, for those it's a native event (and that's most modern browsers).

这篇关于JavaScript .hashchange性能。它会带来任何减速吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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