Skip to main content

Bug Tracker

Side navigation

#8262 closed bug (wontfix)

Opened February 13, 2011 06:10PM UTC

Closed February 14, 2011 08:50PM UTC

try/catch inside jQuery.style() has a negative impact on perf in Safari and Opera

Reported by: lrbabe Owned by:
Priority: low Milestone: 1.next
Component: css Version: 1.5
Keywords: Cc:
Blocked by: Blocking:
Description

To prevent IE from throwing errors when 'invalid' values are provided, the line of code that sets a value to style property has been wrapped by a try/catch (see #5509)

This has a highly negative impact on performance both in Safari5 and Opera11, as shown by this test: http://jsperf.com/try-catch-impact-style#results

We could add a feature test to jQuery to detect when the browser throws an error for an invalid value and add it to jQuery.support.invalidStyle.

We would then change the code in css.js to

jQuery.support.invalidStyle ?
    try { style[ name ] = value; } catch(e) {}:
    style[ name ] = value;
Attachments (0)
Change History (4)

Changed February 13, 2011 07:00PM UTC by lrbabe comment:1

Oops, the try/catch is inside jQuery.style, not jQuery.fn.style

Changed February 13, 2011 07:20PM UTC by jitter comment:2

component: unfiledcss
priority: undecidedlow
status: newopen
summary: try/catch inside fn.style() has a negative impact on perf in Safari and Operatry/catch inside jQuery.style() has a negative impact on perf in Safari and Opera

Changed February 14, 2011 03:08PM UTC by lrbabe comment:3

On the other hand, a patched jQuery performs even worse in Firefox and Opera and only slightly better in Chrome and Safari.

http://jsperf.com/jquery-style-try-catch-impact

It is probably better to leave it as is right now.

Changed February 14, 2011 08:50PM UTC by jitter comment:4

resolution: → wontfix
status: openclosed

Closing as trying to avoid the try/catch makes situation even worse.