开发者

Javascript Running slow in IE - What does "JScript - window script block" mean?

开发者 https://www.devze.com 2022-12-29 22:53 出处:网络
Javascript is running extremely slow on IE on some pages in our site. Profiling seems to show that the following methods are taking the most time:

Javascript is running extremely slow on IE on some pages in our site.

Profiling seems to show that the following methods are taking the most time:

Method                          count inclusive time exclusive time)
 JScript - window script block  2,332      237.98       184.98
 getDimensions                      4          33           33
 eh                               213          32           32
 extend                           446          30           30
 tt_HideSrcTagsRecurs           1,362  开发者_StackOverflow社区        26           26
 String.split                     794          18           18
 $                                717          49           17
 findElements                     104      184.98           14

What does "JScript - window script block" do?

We are using jquery and prototype.


From my experience the main issues on prototype are these:

$$ selectors

Try to use $ selector with down or select instead.

observes

Don't use to many observes. If you want a click handler for more than one element use ids and a global document observe:

document.observe('click', this.clickHandler.bindAsEventListener(this));

clickHandler: function(e)
{
    var elt = e.element();
    while (Object.isElement(elt)) {
         switch (elt.id) {
              //do your stuff here
         }
         elt = elt.up(); //Bubbling
    }
}

CSS selectors with unsupported features on IE

This code will work, but performance will decrease.

<input type="checkbox"/> //HTML
$$('[type=checkbox]') //Prototype

Using a class name will increase performance in this situation:

<input class="checkbox" type="checkbox"/> //HTML
$$('.checkbox') //Prototype

Search on DOM tree

Anything else that require DOM tree search.


I know this question is old, but for anyone getting to it from search results.

I'm pretty sure that "JScript - window script block" is the IE developer tools profiler's term for javascript that's executing in the global scope or in an anonymous function.


If I remember correctly window script bloc has something to do with IE's internet security settings blocking script execution. "Did you noticed the yellow bar?" and questions like that should be appearing on the page.

It all depends on your security zone settings in IE, I think.

http://www.questiontools.com/faq_scriptwarning.html


There is no right answer here because there isn't any example code on what he is doing.

However, the first thing to look at is DOM manipulation in loops. Whenever you touch DOM in loops, its usually a bad idea for performance as DOM manipulation is notoriously slow.

With JavaScript you can vastly reduce DOM manipulation in loops by doing something like this (using jQuery in this example):

// make a container for your DOM additions
var $div = $('<div>'),
i, list = ['a','b','c','d'],
for (i = 0; i < list.length; i++) {
    $div.append( $('<span>').text(list[i]) );
}
// now you can append to the DOM once instead of in a loop
$('body').append($div);

This doesn't just have to do with loops of course. It could be any DOM manipulation being called over and over again such as window.resize or scroll or mouse move or keyup etc etc. Inspect what your code is doing and determine the slowest parts. Start there.


WebKit's SunSpider test (which covers a wide selection of pure-JavaScript functionality). Here is the break down:

Javascript Running slow in IE - What does "JScript - window script block" mean?


(source: ejohn.org)

as you can see, IE is slow on javascript.

source and more here.

0

精彩评论

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

关注公众号