Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6556767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:59:12+00:00 2026-05-25T12:59:12+00:00

I am in the mist of optimising a rather large piece of jQuery code.

  • 0

I am in the mist of optimising a rather large piece of jQuery code. I need help.

Specifically, I have many elements that I want draggable. I have decided to use event delegation to minimise loading time, as briefly discussed here. The problem is that run-time performance is slightly damaged, because the browser has to initialise the dragging at run-time.

Is it possible to use delegation during page loading then, if the browser is inactive, have the elements little by little made draggable through binding? (Some sort of clever asynchronous binding.) That way, I would get high loading and high run-time performance.

Or is there yet an even better approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:59:13+00:00Added an answer on May 25, 2026 at 12:59 pm

    You should simply stick to delegation. There should only be a minimal/near non-existent performance penalty for handling the event after it has bubbled up. However, there absolutely will be a penalty to pay if you end up binding the handler to a lot of elements as you indicate you’re doing, not matter how slowly you do it. Is there a specific other concent you don’t see the delegate handling as the complete solution? I’ve been sitting here thinking for a bit but I can’t recall any specific edge case issues that crop up with that, aside from ie7 an below’s failure at event bubbling, in which case you’re screwed in all ways anyway. You should just be adding a single handler to parent, or the window, and I can’t see how that would cause issues at any point.

    $(selector).live("event names", handler);
    

    which is the same as

    $(window).delegate(selector, "event names", handler)
    

    Both of which only bind a single event handler to a single DOM element.

    I’ve reread the question a few times and I’m not sure if you’re just not firm on how event delegation works or if I missed something in the reading, so apologies if I missed it.

    When you use a delegate handler what you do is create an event listener on a common parent element. DOM events bubble up through the parent chain to window which allows you to have one function listening for events on a lot of elements (if you bind a handler on window then you get pinged on every single event firing of that type that isn’t explicitly stopped from bubbling). An event will identify which element it originally was targeting, so the delegate handler just checks all event targets against the ones it’s been assigned to, and then routes them when it finds an applicable event. That’s as simple something like targetElement["on"+event.name].call(targetElement, event) (libraries like jQuery do some additional stuff for you but that’s the gist). Monitoring the events like this costs nearly nothing so that’s not going to cause any issues.

    The benefits are multifold but the two big ones are:

    1. You only have one event handler at one DOM insertion point consuming memeory and cpu cycles. With the way events bubble and lots of other issues, having copies of an event handler watching different elemnts is always worse performing, significantly worse.

    2. You can bind events to elements that don’t exist yet. Since you can identify them through characteristics such as selectors, you can set up a handler based on that stuff (this normally being how it’s done anyway). If you want to bind an event to a specific element without using delegate handling then you have to have an element creation monitoring and event binding handler, to bind handlers to newly created elements which is a huge overhead as well.

    There’s a handful of exceptions where there are issues caused from delegation. One which arises in IE8 and below causes problems with mouse enter and leave to not fire correctly. These are the cases which demonstrate the need to use something like jQuery specifically when it comes to normalizing DOM quirks. At this point though if you’re not trying to support

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so for the game I'm creating I realized I mist have done something wrong
I have an application that creates a serial key as follows: Take customername Sign
i have this image tag that i'm getting from a weather source that is
Im still in the mist of learning to program, very much lost in that
I need to install a shortcut that opens one of the folders that I'm
In my web application, I have 2 users and 2 roles. I want to
I have a Rails 3.2 Application that is hosted on Heroku. I would like
I'm working on a small wrapper for the Growl 1.3.1 SDK. More specifically, I'd
How can I disable an input-field with jQuery using GM if the url contains
I reading Rails Tutorial and created a Sample_App. My code is available here: https://github.com/namic/sample_app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.