I am going to work on a project developped by someone else. I don’t have any contact with this guy.
I noticed a very high cpu consumption by the browser when the page is loaded.
After some investigations, i think that the problem comes from a patch of jquery regex but I don’t clearly understand the goal of this patch and the cause of this cpu consumption.
jQuery.expr[':'].regex = function(elem, index, match) {
var matchParams = match[3].split(',');
var validLabels = /^(data|css):/;
var attr = {
method:
matchParams[0].match(validLabels) ? matchParams[0].split(':')[0] : 'attr',
property: matchParams.shift().replace(validLabels,'')
};
var regexFlags = 'ig';
var regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags);
return regex.test(jQuery(elem)[attr.method](attr.property));
};
I have seen that this method was constanly called.
I have several calls to regex like this one.
$(':regex(id,DelCompo.*$)').livequery('click',function(e) {
//...
}
If I comment them, the cpu consumption seems to be normal. Of course, some features are broken.
I think the problem comes from this new regex function. Is it correct?
What would be the best way to fix this problem?
Thanks
FYI, I fixed it by not using regex in the jquery selector. I guess that this was not the right choice for my document.