Matt H Matt H - 1 year ago 90
Javascript Question

Why is RegExp.test consuming a lot of time in IE?

When using jQuery to load HTML into an element, I am seeing very poor performance in IE. Chrome is not showing any performance problems. Changing the IE browser mode does not appear to improve the performance.

When running the profiler in IE, I see that most of the time is being spent in the



<div id="content"></div>


var htmlString = <div>...Lots and lots of content...</div>


  • jQuery version: 1.9.1

  • IE version: 9

Answer Source

When loading a large amount of content, don’t start with an opening tag and end with the closing tag.

Change content to: var htmlString = <div></div><div>...Lots and lots of content...</div>

After researching the problem I found this jQuery bug request that pointed me in the right direction. jQuery Ticket #11456

It appears that for IE compatibility, JavaScript RegExp is used to parse the content that is being loaded. When the content starts with a tag, it tries to find the end tag (or something like that). If the amount of data is large, it can take quite a while to do this parsing. I solved my problem by putting an empty at the beginning.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download