Forums | MacLife

Wide is the new black

You are not logged in.

#1 2008-07-11 12:37 am

matt
Screw it
Registered: 1999-09-16
Posts: 16204
Website

Adding event handlers: Is one way faster?

I made a phpbb3 theme last year, and recently I've been updating it to make it completely xhtml-1.1-compliant.

While doing this I decided to remove the use of innerHTML and any event handlers that might not work in the most proper way.

First I removed all inline HTML event handlers and moved them all to external javascript files or to commented code within the page.

But after that, I decided to remove any instances of events added like

Code:

thisElement.onclick = function ()
{
    doThis();
}

and replace them with

Code:

thisElement.addEventListener('click', function ()
{
  doThis();
}, false)

I assumed that removing all inline HTML event handlers would decrease page load times, but the second change seems to have also decreased them.

Is using addEventListener really faster than just using onclick= or am I just feeling a placebo effect?

Offline

 

#2 2008-07-11 12:42 am

matt
Screw it
Registered: 1999-09-16
Posts: 16204
Website

Re: Adding event handlers: Is one way faster?

And just for clarification, when I ask about decreasing page load times, I am referring to the time taken for code that executes as a page loads.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson