mootools_使用MooTools更快地进行DOMReady检查

mootools

Digging into the source code of your favorite JavaScript framework is essential to becoming a {insert framework here} rock star. Digging into other JavaScript frameworks is essential to opening your mind about JavaScript and can give you new ideas to implement improvements in your favorite framework. I was recently looking at the jQuery source code and found that jQuery checks to see if the DOM is ready every 13 milliseconds. MooTools does this same check every 50 milliseconds. Speeding up MooTools' DOMReady check, however, is as easy as updating a periodical's interval.

挖掘最喜欢JavaScript框架的源代码对于成为{insert framework here}摇滚明星至关重要。 深入研究其他JavaScript框架对于打开您JavaScript视野至关重要,并且可以为您提供新的想法,以实现您喜欢的框架中的改进。 我最近在查看jQuery源代码,发现jQuery每隔13毫秒检查一次DOM是否准备就绪。 MooTools每50毫秒执行一次相同的检查。 但是,加快MooTools的DOMReady检查就像更新期刊的间隔一样容易。

MooTools JavaScript (The MooTools JavaScript)


var repeat;
if (Browser.ie){
	var temp = document.createElement('div');
	repeat = function(){
		(Function.stab(function(){
			temp.doScroll(); // Technique by Diego Perini
			return document.id(temp).inject(document.body).set('html', 'temp').dispose();
		})) ? domready() : repeat.delay(50);
	};
	repeat();
} else if (Browser.safari && Browser.version < 4){
	repeat = function(){
		(['loaded', 'complete'].contains(document.readyState)) ? domready() : repeat.delay(50);
	};
	repeat();
} else {
	document.addEvent('DOMContentLoaded', domready);
}


The above code is the important piece of the DOMReady utility file. You'll see ".delay(50)" twice in that code block; that's the number we'll update:

上面的代码是DOMReady实用程序文件的重要组成部分。 您将在该代码块中看到两次“ .delay(50)”。 那就是我们要更新的数字:


//....more code
repeat.delay(20);


Voila! Faster DOMReady checks!

瞧! 更快的DOMReady检查!

To my knowledge, there's no science to what that number should be so don't feel as though I'm saying you should modify this number. Just wanted to let you know it was possible!

据我所知,这个数字应该是多少还没有科学依据,所以不要觉得我是在说应该修改这个数字。 只是想让您知道这是可能的!

翻译自: https://davidwalsh.name/mootools-domready

mootools

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值