非阻塞Javascript [英] Non-blocking Javascript

查看:125
本文介绍了非阻塞Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以以不阻止用户体验的方式加载javascript。我不知道如何实现相同,但我正在寻找一个跨浏览器的解决方案。我想知道是否有人可以指导我朝着正确的方向前进。将js放在页面底部不能很好。



感谢您的时间。

解决方案

Javascript在一个单线程中运行,所以如果你有大量的Javascript调用,那么就像ExtJS这样的librairies一样,它很慢是正常的。但是,您可以考虑以下备选方案:



首先,尽量优化代码。



然后,您可以在Javascript中使用计时器来模拟异步工作。以下是如何执行此操作的一个很好的示例: http://ejohn.org/blog / how-javascript-timers-work /



如果您想了解更多信息,请参阅以下有关如何尝试减少Javascript冻结时间的其他提示。 / p>

http://debuggable.com/posts/run-intense-js-without-freezing-the-browser:480f4dd6-f864-4f72-ae16-41cccbdd56cb



祝你好运!


I am wondering if it is possible to load javascript in a way in which it does not block the user experience. I am not sure how to achieve the same, but I am looking for a cross-browser solution. I am wondering if someone can guide me in the right direction. Placing the js at the bottom of the page does not work too well.

Thank you for your time.

解决方案

Javascript runs in a single-thread, so if you have massive Javascript calls, let say with librairies like ExtJS, it's normal that it can be slow. You might however consider the following alternatives:

First and foremost, try to optimize the code as much as you can.

Then, you could use timers in Javascript to simulate asynchronous work. Here is a good example on how to do this : http://ejohn.org/blog/how-javascript-timers-work/

If you want more information, here are some additional tips on how to attempt to reduce Javascript freezing time.

http://debuggable.com/posts/run-intense-js-without-freezing-the-browser:480f4dd6-f864-4f72-ae16-41cccbdd56cb

Good luck !

这篇关于非阻塞Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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