GithubHelp home page GithubHelp logo

haydermabood / dom-pool Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chrisantaki/dom-pool

0.0 0.0 0.0 15 KB

:recycle: Recycle DOM nodes to increase efficiency.

JavaScript 89.02% HTML 10.98%

dom-pool's Introduction

dom-pool

Let your app focus on rendering 60fps. Avoid creating & GC'ing DOM nodes on the fly.

Installation

npm install dom-pool --save

Usage

// Grab the library from NPM or Bower.
const Pool = require('dom-pool');

// Create a new Pool for a specific DOM tagName, like "div".
const divPool = new Pool({
  tagName: 'div'
});

// Pools have an Array-like syntax: "pop" & "push".
const div = divPool.pop();

// ... let's imagine doing awesome stuff with the DIV ...

// Once you're done with the DIV, return it to the Pool with "push".
divPool.push(div);

// Next time "pop" is called, your app can efficiently reuse the DIV.

// To create DIVs ahead of time, use the "allocate" method.
divPool.allocate(100);

Custom namespaces

// SVG is also supported.
// We just need to specify its namespace.
const circlePool = new Pool({
  namespace: 'http://www.w3.org/2000/svg',
  tagName: 'circle'
});

// Let's allocate 128 circles.
circlePool.allocate(128);

What performance gains can I expect?

Reusing DOM elements is 2-6 times faster than creating DOM elements.

Performance

Now is this performance totally free? Not exactly. When you create a DOM element, it's like a blank slate. When you reuse a DOM element, it keeps the attributes you've given it. However, if you're going to be updating those same attributes anyways, it's basically free.

What browsers are supported?

Modern browsers & IE9+. If you're sticking to HTML nodes then IE5+ is supported. The reason being, IE added support for createElementNS in version 9.

Screenshots of dom-pool in use, with Chrome DevTools

Note the DOM node count over time.

Pooling DOM nodes

Creating DOM nodes

dom-pool's People

Contributors

chrisantaki avatar amilajack avatar matthewvita avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.