编程语言
首页 > 编程语言> > javascript-是否有用于在浏览器中滚动的特殊线程?

javascript-是否有用于在浏览器中滚动的特殊线程?

作者:互联网

我正在为我的一个类编写一个JavaScript教程,我想说明一下调用堆栈可以阻止其他进程,并且在这种情况下,页面交互将排队,直到调用堆栈为空.

const print = function(){
	console.log( "Hello World" );
}
setTimeout(print,0);
for(let i=0 ; i < 2000000000 ; i++);
console.log();

运行上面的代码后,我让他们单击链接并调整窗口大小,以查看该页面没有重新呈现,但是在Stack Overflow之类的许多网站上滚动似乎都可以正常工作.它在Reddit上被阻止.我已经在Chrome和Firefox上对此进行了测试,以仔细检查是否进行了一些优化,但是其表现类似.

我假设一个站点上没有与滚动相关的事件的事件处理程序,那么有一个用于基本滚动的特殊线程.这是因为我注意到带有粘性标头的站点将允许滚动,但直到循环结束后才具有粘性效果.

解决方法:

我在下面链接到的Microsoft博客,文章由Nolan Lawson撰写,关于此确切问题,有很多很好的信息-请仔细阅读.这是该博客文章的摘录:

As it turns out, the whole “browsers are single-threaded” story is largely true, but there are important exceptions. Scrolling, in all its various flavors, is one of those exceptions.

Over the years, browser vendors have recognized that offloading work to background threads can yield enormous improvements to smoothness and responsiveness. Scrolling, being so important to the core user experience of every browser, was quickly identified as a ripe target for such optimizations. Nowadays, every major browser engine (Blink, EdgeHTML, Gecko, WebKit) supports off-main-thread scrolling to one degree or another (with Firefox being the most recent member of the club, as of Firefox 46).

资料来源:Scrolling on the web: A primer

标签:blocking,dom-events,javascript
来源: https://codeday.me/bug/20191024/1923358.html