Why everyone should stop using particles.js right now
Matteo Bruni
Posted on February 21, 2022
Should I stop using particles.js? Why?
Yes, a lot of devs are using particles.js for their websites displaying simple and cool particles animations.
46 millions (at the moment of writing) of monthly requests on JSDelivr, not bad I should say. But all these websites can have a better alternative, instead of using an old library with a HUGE memory leak.
Memory leak? Uh?
If you don't believe me, test it out yourself below
And if you don't trust me, the button code is not a classic click counter, it's a counter of the particles.js instances.
This is the code used in the CodePen, it's already visible but it's easier to read it here. Feel free to test it in your particles.js
After a few clicks the button is not responding, am I right?
Isn't it enough?
If you have a screen with more than 60hz refresh rate, try changing it and see the sample with Chrome, is it getting slower or faster depending on the refresh rate, right?
Lot of devices are getting 120hz refresh rate, or even 144hz, and I don't think you want different animations with different rates.
So what should you do?
There's already a libary fixing all these issues, and many other that you can read here
The replacing library is tsParticles, which can start also with a particles.js configuration.
Be careful when upgrading from particles.js, tsParticles has a default fullScreen option set, so particles will start set as background with a z-index: 0, and the particles.move.speed needs to be slowed down, since particles.js has a bug (strange, uh?) with that value, horizontal and vertical particles were faster than the others.
With the migration, you'll get also confettis, fireworks, particles spawning from areas, more interactions, more particles shapes, and more...
tsParticles is already being used a lot:
212 millions (at the moment of writing) of monthly requests on JSDelivr, 166 millions more than particles.js, and you can be part of this change.
Ok, lot of words, but here's the proof that almost the same code is not having a memory leak
tsParticles - no memory leak
Again, the button is not faking the update, here's the code:
tsParticles - Easily create highly customizable JavaScript particles effects, confetti explosions and fireworks animations and use them as animated backgrounds for your website. Ready to use components available for React.js, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Inferno, Solid, Riot and Web Components.
tsParticles - TypeScript Particles
A lightweight TypeScript library for creating particles. Dependency free (*), browser ready and compatible with
React.js, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Inferno, Riot.js, Solid.js, and Web Components