A href vs onclick - performance test -
IE6 vs IE7 vs FF3 vs
FF2 vs Chrome vs
Opera vs Safari

4 min read >

AHrefs vs OnClick – Performance tests on different browsers

Engineering Insights & Web Platforms

While optimizing some HTML code, I recently came across the question: when rendering anchors, which of the href and onclick are rendered quicker by the browsers. To find out, I created two files, each one with 330.480 anchors, one only with onclick event: onclick=’vc(‘4280220′)’ and another one only with hrefs: href=’javascript:vc(‘4280220′)’.

The files have over 17 and 14 megs (the one with hrefs being larger due to more text). Here’s the beginning of each file:

  • href:
        <a class="”td”">-</a>
        <a class="”td”">-</a>
        … 330.478 more
  • onclick:
        <a class="td">-</a>
        <a class="td">-</a>
        … 330.478 more

The “td” class used is necessary since rendering the anchors with href results in underlining the text, thus consuming more CPU power for drawing the page, than the anchors with onclick which do not get underlined.

The environment on which the test was performed is a Windows XP SP2 machine with Multiple IEs for testing on both IE7 and IE6 as well as Firefox 2, Firefox 3, Chrome, Opera, and Safari. The rendering time on one browser is not important (which is why I don’t mention hardware indicators), but the actual time comparison between all the browsers. Let’s see the results first:

IE vs FF vs Chrome vs Opera vs Safari

If you however are a hardcore programmer who needs those extra seconds, Internet Explorer is the only one that renders href-s much quicker than onclick-s. All the other browsers render onclick-s faster than href-s. If your website will be accessed by a wide audience of users, given that IE has still the biggest share of the browser market, you may want to render your anchors using href-s.

Apart from the hrefonclick comparison, there are some surprises in this graph. For example, FF3, although much faster than FF2 or IE at rendering complex pages and javascript, performs the slowest of all browsers. Opera is the fastest browser, while Firefox 2 does almost the same job as Internet Explorer 7.

IE6 renders the page with href-s incredibly faster, but at the same time, it took more than 5.5 minutes to render the page with onclick event (I eventually killed the process after 5.5 minutes). This may be due to Multiple IEs, so the second result for IE6 is questionable.

And the newest kid in the block, Chrome behaves better than Firefox 3 but much slower than Firefox 2.

While this test may give a slight idea of how fast these browsers perform with this specific test case, it is not relevant for regular HTML pages filled with various elements (div-s, span-s, br-s, p-s, etc). For those pages, as probably everyone has noticed, FF3 renders the page much faster than IE7, IE6, or FF2.