Re: [whatwg/dom] MutationObserver with querySelector for elements (#77)

A huge use case for this would be attaching events to elements before DOMContentLoaded.
Currently, most scripts add events to elements on DOMContentLoaded which on slow networks and/or large pages can take quite a while. In the meantime, users see a UI that doesn’t work, and don’t know when it will start working (since DOMContentLoaded is not something a user can train to recognize).

MutationObserver has the potential to fix this very pervasive problem and give developers the power to attach events to elements as they are rendered. However, currently that would require looping over every single element and using `.matches()` on it, which would be very expensive in exactly the case where it matters most (pages with lots of HTML).

If the platform could do most of this filtering efficiently, then using MO for this would be a feasible solution. It doesn’t have to be the entire selector syntax, but at least tags, classes, ids, attributes (partial too).

I wonder if we could mine jQuery code (since that has a very specific pattern of `$(selector).eventName(callback)` while in vanilla JS it’s done in many different ways) to see what types of selectors people use. It might be an even more restricted set.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/77#issuecomment-369432682

Received on Thursday, 1 March 2018 00:32:43 UTC