开发者

HTML5 web workers for binding jQuery events (what about IE?)

开发者 https://www.devze.com 2023-01-28 08:12 出处:网络
HTML5 workers is a very interesting concept for avoiding a locked up user-interface. For a shop application I\'m listing a larger amount of product-widgets for which I have to activate functionality,

HTML5 workers is a very interesting concept for avoiding a locked up user-interface.

For a shop application I'm listing a larger amount of product-widgets for which I have to activate functionality, using jQuery bindings.

Would I be able to use web workers to perform this task so that the page will re开发者_如何学JAVAsponsive much sooner?

The support for web workers is lacking in IE but would be be possible to implement/simulate something simular until support arrives?

I found this implementation for IE and older browsers http://code.google.com/p/ie-web-worker/


Yes, web workers don't lock the DOM, so using them speeds up rendering.

The only alternative to web workers is using a succession of short functions called with window.setTimeout, but this will lock the DOM.

edit: the ie alternative you found isn't quite the same. Because it doesn't perform pre-emptive multitasking (how can it), if you run a long running script the browser will think the page had crashed whereas it wouldn't in chrome, firefox etc.

So basically, because you need to access the DOM. Split your tasks up into fairly large parts (50ms at most) then put each part in a window.setTimeout and let the browser schedule them. If the parts are too small the browser will waste time.


Web workers will be useful if you're doing long running scripts. Offloading long running scripts to a "worker" process will keep your UI responsive, as the worker won't block your UI. Unfortunately, I'm not aware of any great shims / polyfills for web workers for IE (unless the IE user has Google Gears installed). I've found that the best way to keep your app responsive is to use web workers for browsers that support it, but degrade to using setTimeout (about every 100ms) for browsers that don't.

If you're interested in the Google Gears based shim, here it is: http://html5-shims.googlecode.com/svn/trunk/demo/workers.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号