dom VS IntersectionObserver

Compare dom vs IntersectionObserver and see what are their differences.

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
dom IntersectionObserver
30 6
1,535 3,621
1.8% 0.1%
6.5 5.0
7 days ago about 1 month ago
HTML Bikeshed
GNU General Public License v3.0 or later GNU General Public License v3.0 or later
The number of mentions indicates the total number of mentions that we've tracked plus the number of user suggested alternatives.
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.

dom

Posts with mentions or reviews of dom. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2024-04-25.
  • A Response to "Have Single-Page Apps Ruined the Web?"
    3 projects | news.ycombinator.com | 25 Apr 2024
    in plain htmx, you can target an area that doesn't disrupt a playing video (e.g. the comments box appending to the comments) or you can use a morphing algorithm that disrupts the DOM less.

    i have my own morphing algorithm (and a corresponding htmx plugin that allows you to use it) called idiomorph:

    https://github.com/bigskysoftware/idiomorph/

    i've also been working with the chrome team to get a feature added they are calling "atomic moves":

    https://github.com/whatwg/dom/issues/1255

    this would allow us to move elements around in the DOM without losing things like play state or focus or whatever

    very excited for this last idea, I think it will be a huge boon for the web in general, not just for htmx

  • HTML Attributes vs. DOM Properties
    2 projects | news.ycombinator.com | 24 Apr 2024
    What I said in my previous comment is observably true. Try making a demo where it isn't.

    > A DOM node is a living mutable thing, but the JavaScript object representing that node is not.

    The JavaScript object is mutable. The first example in the article shows this.

    > That is also why a node list is not an array.

    Modern APIs on the web return platform arrays (eg JavaScript arrays). https://webidl.spec.whatwg.org/#js-sequence - here's where the WebIDL spec specifies how to convert a sequence to a JavaScript array.

    I'm fully aware of NodeList. There's a reason the spec calls them "old-style" https://dom.spec.whatwg.org/#old-style-collections

    > I can understand how this is confusing if you have never operated without a framework, but otherwise it’s really straightforward

    Sighhhhhh. I've been a web developer for over 20 years, and spent a decade on the Chrome team working on web platform features. Most of my career has been on the low-level parts of the platform.

    Could it be possible that people are disagreeing with you, not because they're stupid, but because you're in the wrong? Please try to be open minded. Try creating some demos that test your opinions.

  • Using XPath in 2023
    8 projects | news.ycombinator.com | 16 Jul 2023
    Domenic Denicola (the man who ruined promises) probably will as well.

    https://github.com/whatwg/dom/issues/67

  • Which browser do you recommend, one for personal security-focused use and one for work?
    1 project | /r/browsers | 8 Jun 2023
    I'm pretty sure it is, since I get "TypeError: nodes[i].parentNode.href is undefined" and "TypeError: $mainmenu.parent(...).get(...) is undefined" errors on both Pale Moon and LibreWolf. Which is part of Shadow/DOM, and originated from google (https://hacks.mozilla.org/2015/06/the-state-of-web-components/). Not sure when this particular thing was introduced, since it's a "living standard"/experimental feature (https://dom.spec.whatwg.org/).
  • That people produce HTML with string templates is telling us something
    16 projects | news.ycombinator.com | 26 May 2023
    JSX chose to align names to the DOM spec [0]. Same for htmlFor and friends.

    [0] https://dom.spec.whatwg.org/#ref-for-dom-element-classname%E...

  • Notback BETA - A new PHP frontend framework
    5 projects | /r/PHP | 28 Mar 2023
    You can see why I say this here: https://dom.spec.whatwg.org
  • Understanding the Benefits of "Quirky" Web Languages
    6 projects | dev.to | 28 Mar 2023
    The product logos in this article's cover image include different languages and technologies some of which are still relevant for web development today: HTML, CSS, JavaScript / ES / TypeScript (and the DOM), SVG, PDF, PHP, SQL (mySQL, MariaDB), mongoDB, Node.js (the most successful server-side implementation of JavaScript so far).
  • Declarative Shadow DOM
    5 projects | news.ycombinator.com | 13 Feb 2023
    Thanks for the shout-out! I think I mention this in the talk, but note that YMMV. I designed that benchmark as a kind of "worst-case scenario" where shadow DOM / scoped styles really show a benefit. Depending on your CSS rules, DOM size, and amount of thrashing, the perf benefit could be small to large.

    Also, it's still possible to shoot yourself in the foot, especially if you have a large/complex stylesheet repeated across multiple shadow roots. (Not because of the repetition – that's optimized in browsers [1] – but rather because of the number of DOM nodes affected.)

    That said, I still think the perf benefits of shadow DOM have been undersung. And Declarative Shadow DOM makes it way more useful.

    [1]: https://github.com/whatwg/dom/issues/831#issuecomment-585489...

  • HTML DOM ️loves Javascript! 💕 #TLA 😘
    1 project | dev.to | 23 Jan 2023
    We luh-luh-luv you! They gestated and nurtured the spec. They fought over bike sheds! All for us!!
  • AI Found a Bug in My Code
    3 projects | news.ycombinator.com | 16 Nov 2022

IntersectionObserver

Posts with mentions or reviews of IntersectionObserver. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2021-07-28.
  • Lazy loading of images in masonry layout?
    1 project | /r/nicegui | 7 Jul 2023
    You should only create the images (or set the src) for the images which are visible to the user. See our infinite scroll example for a naive implementation. More elaborated code might use the https://www.w3.org/TR/intersection-observer/.
  • Safari isn't protecting the web, it's killing it
    3 projects | news.ycombinator.com | 28 Jul 2021
    I got a little curious on the statuses of these standards and went on a bit of searching.

    > CSS contain (CSS Containment Module Level 2) - First published in 2019, still Editor's Draft[1]. Not supported by Safari/WebKit.

    > CSS offset-path (Motion Path Module Level 1) - First published in 2015, still Editor's Draft[2]. Not supported by Safari/WebKit.

    > CSS overflow-anchor (CSS Scroll Anchoring Module Level 1) - First published in 2020, still Editor's Draft[3]. Not supported by Safari/WebKit.

    > Resolution media queries (dppx) - W3C Recommendation since 2012[4]. Not supported by Safari/WebKit.

    > :focus-visible (Selectors Level 4) - First published in 2011, still Editor's Draft[5]. Not supported by Safari/WebKit.

    - Touch Events - W3C Recommendation since 2013[6]. Supported on iOS 3.2 (2010). I assume the author meant Pointer Events[7] which became W3C recommendation since 2019, and supported on 13.2 (2019).

    > BroadcastChannel - WHATWG Living Standard[8]. Blocked by privacy concern on WebKit side since 2020[9]. Initial support landed in WebKit trunk as of 2021-07.[10]

    > beforeprint/afterprint - WHATWG Living Standard[11]. Supported by Safari/WebKit since 2019 (iOS 13).

    > Regex Lookbehind - ECMAScript 2018[12]. Not supported by Safari/WebKit.

    > scrollIntoView (CSSOM View Module) - First introduced in CSSOM View Module since 2011, still Editor's Draft[13]. Not supported by Safari/WebKit.

    > Screen Orientation API - First committed in wc3/screen-orientation in 2012, still a W3C Working Draft[14]. Not supported by Safari/WebKit.

    > Date and time input types - WHATWG Living Standard[15], partial support by Safari/WebKit since 2012 (iOS 5) but no week/min/max.

    > Service Workers - W3C Candidate Recommendation since 2019[16]. Supported by Safari/WebKit since 2018 (iOS 14.5).

    - AbortSignal - WHATWG Living Standard[17]. Supported by Safari/WebKit since 2018 (iOS 11.3)

    - Intersection Observer - First published in 2017, still W3C Working Draft[18]. Supported by Safari/WebKit since 2019 (iOS 12.2).

    - Client-side form validation - WHATWG Living Standard[19]. Supported by Safari/WebKit since 2017 (iOS 10.3).

    [1]: https://drafts.csswg.org/css-contain/#contain-property

    [2]: https://drafts.fxtf.org/motion/#offset-path-property

    [3]: https://drafts.csswg.org/css-scroll-anchoring/#exclusion-api

    [4]: https://www.w3.org/TR/css3-mediaqueries/#resolution

    [5]: https://drafts.csswg.org/selectors-4/#the-focus-visible-pseu...

    [6]: https://www.w3.org/TR/touch-events/

    [7]: https://www.w3.org/TR/pointerevents/

    [8]: https://html.spec.whatwg.org/multipage/web-messaging.html#br...

    [9]: https://github.com/whatwg/html/issues/5803

    [10]: https://bugs.webkit.org/show_bug.cgi?id=227924

    [11]: https://html.spec.whatwg.org/multipage/timers-and-user-promp...

    [12]: https://262.ecma-international.org/9.0/

    [13]: https://drafts.csswg.org/cssom-view/#dom-element-scrollintov...

    [14]: https://www.w3.org/TR/screen-orientation/

    [15]: https://html.spec.whatwg.org/multipage/input.html#date-state...

    [16]: https://www.w3.org/TR/service-workers/

    [17]: https://dom.spec.whatwg.org/#abortsignal

    [18]: https://www.w3.org/TR/intersection-observer/

    [19]: https://html.spec.whatwg.org/multipage/forms.html#client-sid...

  • Revealing Contents on Scroll Using JavaScript’s Intersection Observer API
    2 projects | dev.to | 22 May 2021
    W3.Org
  • Adding IntersectionObserver polyfill
    1 project | /r/nextjs | 5 May 2021
    I've used https://github.com/w3c/IntersectionObserver/tree/main/polyfill in the past and it's pretty much just import and forget.
  • Endless Scroll / Infinite Loading with Turbo Streams & Stimulus
    4 projects | dev.to | 3 May 2021
    // app/javascript/controllers/infinite_scoll_controller.js import { Controller } from "stimulus" export default class extends Controller { static targets = ["scrollArea", "pagination"] connect() { this.createObserver() } createObserver() { const observer = new IntersectionObserver( entries => this.handleIntersect(entries), { // https://github.com/w3c/IntersectionObserver/issues/124#issuecomment-476026505 threshold: [0, 1.0], } ) observer.observe(this.scrollAreaTarget) } handleIntersect(entries) { entries.forEach(entry => { if (entry.isIntersecting) { this.loadMore() } }) } loadMore() { const next = this.paginationTarget.querySelector("[rel=next]") if (!next) { return } const href = next.href fetch(href, { headers: { Accept: "text/vnd.turbo-stream.html", }, }) .then(r => r.text()) .then(html => Turbo.renderStreamMessage(html)) .then(_ => history.replaceState(history.state, "", href)) } }
  • Create an infinite scrolling blog roll in Rails with Hotwire
    2 projects | dev.to | 22 Mar 2021
    import { Controller } from "stimulus" export default class extends Controller { static targets = ["entry"] static values = { path: String, } connect() { this.createObserver(); } createObserver() { let observer; let options = { // https://github.com/w3c/IntersectionObserver/issues/124#issuecomment-476026505 threshold: [0, 1.0] }; observer = new IntersectionObserver(entries => this.handleIntersect(entries), options); observer.observe(this.entryTarget); } handleIntersect(entries) { entries.forEach(entry => { if (entry.isIntersecting) { // https://github.com/turbolinks/turbolinks/issues/219#issuecomment-376973429 history.replaceState(history.state, "", this.pathValue); } }); } }

What are some alternatives?

When comparing dom and IntersectionObserver you can also consider the following projects:

hyperHTML - A Fast & Light Virtual DOM Alternative

turbo-rails - Use Turbo in your Ruby on Rails app

extension-manager - A utility for browsing and installing GNOME Shell Extensions.

rails-infinite-scroll-posts - Learn how to create an infinite scrolling blog roll in Rails with Turbo and Stimulus.

brutal - 🏢 An operating system inspired by brutalist design that combines the ideals of UNIX from the 1970s with modern technology and engineering

Intersection-Observer

Isotope - :revolving_hearts: Filter & sort magical layouts

WHATWG HTML Standard - HTML Standard

turbo - Incremental bundler and build system optimized for JavaScript and TypeScript, written in Rust – including Turbopack and Turborepo.

domdiff - Diffing the DOM without virtual DOM

turbo - The speed of a single-page web application without having to write any JavaScript