JavaScript .hashchange性能。它会带来任何减速吗?

编程入门 行业动态 更新时间:2024-10-28 14:29:51
本文介绍了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性能。它会带来任何减速吗?

本文发布于:2023-11-04 00:25:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556462.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:它会   性能   JavaScript   hashchange

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!