Introducing Bliss: A 3KB library for happier Vanilla JS

Screen Shot 2015-12-04 at 16.59.39Anyone who follows this blog, my twitter, or my work probably is aware that I’m not a huge fan of big libraries. I think wrapper objects are messy, and big libraries are overkill for smaller projects. On large projects, one uses frameworks like React or Angular anyway, not libraries.

Anyone who writes Vanilla JS on a daily basis probably is aware that it can sometimes be, ahem, somewhat unpleasant to work with. Sure, the situation is orders of magnitude better than it was when I started. Back then, IE6 was the dominant browser and you needed a helper function to even add event listeners to an element (remember element.attachEvent?) or to get elements by a class!


Fun fact: I learned JavaScript back then by writing my own library, called jAsset. I had not heard of jQuery when I started it in 2007, so I had even coded my own selector engine! (Anyone remember slickspeed?) jAssset had plenty of nice helper functions, its own UI library and a cool logo. I had even started to make a website for its UI components, seen on the right.

Sadly, jAsset died the sad inevitable death of all unreleased projects: Without external feedback, I had nobody to hold me back from adding to its API every time I personally needed a helper function. And adding, and adding, and adding… Until it became 5000+ loc long and its benefit of being lightweight or comprehensible had completely vanished. It collapsed under its own weight before it even saw the light of day. I abandoned it and went through a few years of using jQuery as my preferred helper library. Eventually, my distaste for wrapper objects, the constantly improving browser support for new APIs that made Vanilla JS more palatable, and the decline of overly conspicuous browser bugs led me to give it up.

It was refreshing, and educational, but soon I came to realize that while Vanilla JS is orders of magnitude better than it was when I started, certain APIs are still quite unwieldy, which can be annoying if you use them often. For example, the Vanilla JS for creating an element, with other elements inside it, events and inline styles is so commonly needed, but also so verbose and WET, it can make one suicidal.

However, Vanilla JS does not mean “use no abstractions”. Programming is all about abstractions! The Vanilla JS movement, is about favoring speed, smaller abstractions and understanding of the Web Platform, over big libraries that we treat as a black box. It’s about using libraries to save time, not to skip learning.

So, I used my own tiny helpers, on every project. They were small and easy to understand, instead of several KB of code aiming to fix browser bugs I will likely never encounter and let me create complex nested DOM structures with a single JSON-like object. Over time, their API solidified and improved. On larger projects it was a separate file which I had tentatively codenamed Utopia (due to the lack of browser bug fixes and optimistic use of modern APIs). On smaller ones just a few helper methods (I could not live without at least my tiny 2 sloc $() and $$() helpers!). Here is a sample from my open source repos:

Notice any recurring themes there? 🙂

I never mentioned Utopia.js anywhere, besides silently including it in my projects, so it went largely unnoticed. Sometimes people would look at it, ask me to release it, I’d promise them I would and then nothing. A few years ago, someone noticed it, liked it and documented it a bit (site is down now it seems). However, it was largely my little secret, hidden in public view.

For the past half year, I’ve been working hard on my research project at MIT. It’s pretty awesome and is aimed at helping people who know HTML/ CSS but not JS, achieve more with Web technologies (and that’s all I can say for now). It’s also written in JS, so I used Utopia as a helper library, naturally. Utopia evolved even more with this project, got renamed to Bliss and got chainability via my idea about extending DOM prototypes without collisions (can be disabled and the property name is customizable).

All this worked fine while I was the only person working on the project. Thankfully, I might get some help soon, and it might be rather inexperienced (the academia equivalent of interns). Help is very welcome, but it did raise the question: How will these people, who likely only know jQuery, work on the project? [1]

The answer was that the time has come to polish, document and release Bliss to the world. My plan was to spend a weekend documenting it, but it ended up being a little over a week on and off, when procrastinating from other tasks I had to do. However, I’m very proud of the resulting docs, so much that I gifted myself a domain for it. They are fairly extensive (though some functions still need work) and has two things I always missed in other API docs:

  • Recommendations about what Vanilla JS to use instead when appropriate, instead of guiding people into using library methods even when Vanilla JS would have been perfectly sufficient.
  • A “Show Implementation” button showing the implementation, so you can both learn, and judge whether it’s needed or not, instead of assuming that you should use it over Vanilla JS because it has magic pixie dust. This way, the docs also serve as a source viewer!

So, enjoy Bliss. The helper library for people who don’t like helper libraries. 🙂 In a way, it feels that a journey of 8 years, finally ends today. I hope the result makes you blissful too.

Oh, and don’t forget to follow @blissfuljs on twitter!

[1]: Academia is often a little behind tech-wise, so everyone uses jQuery here — hardly any exceptions. Even though browser support doesn’t usually even matter to research projects!

  • I have been trying to get rid of jQuery for interactive mocks I have to make at my day job. Working with vanilla js has not been very pleasant there. So this definitely looks like something I am gonna try out and get you some feedback. Thanks 🙂

    • Let me know how it was if you do!

  • Pingback: 3 – Introducing Bliss: A 3KB Library for Happier Vanilla JavaScript | Lea Verou - Exploding Ads()

  • Hjoaco Mg

    Excellent! 🙂

  • Dan

    Lost me at “…one uses frameworks like React…” React is a library. Not a framework.

    • Hannan Ali

      React is pretty much a framework

      • tehbrthtehhrtehteh

        Facebook, the owner and creator, calls it a library, so it is a library.

        • Hannan Ali

          @charlesantoinegiroux:disqus Explaination is much better than yours. Facebook owner’s saying is not a criteria for a coding project to be called a framework.

      • Charles-Antoine Giroux

        Hmmm no. React is missing too* many things out of the box to be called a framework. You really cannot compare React to Angular without adding other libraries to React. This is kind of the beauty of React, you can use React + X + Y or React + A + D to make your hmm “Front-end Framework”. TBH though, I think we all know what Lea meant and that Dan is an asshole.


        • Hannan Ali

          Thanks for the explanation.

  • While I don’t join the jquery backlash crowd, this looks like a really interesting library and I think picking its code apart will no doubt provide some solid learning. Kudos!

  • Pingback: Дайджест интересных материалов из мира веб-разработки и IT за последнюю неделю №188 (1 — 6 декабря 2015) -

  • Pingback: – dahinter :: behind » Tweet :: RT @LeaVerou: World, meet Bliss: A 3KB library for…()

  • Haim Yulzari

    This sounds very interesting. I tried the snippet{
    “color”: “green”

    and it worked as expected on Chrome and Firefox. When I got to IE11 it failed, complaining “out of stack space” and pointing to bliss.js, Line 314, Column 2.

    I hope there is a fix because I really like this library and must support IE.

  • “On large projects, one uses frameworks like React or Angular anyway, not libraries.”
    You mean “large libraries”, I suppose? I work on AngularJS applications, and they use lot of libraries… 🙂
    And, pet peeve: React isn’t a framework, it is a library. And an ecosystem. I suppose when people talk about React as a framework, they think about the ecosystem…

    That said, I like your site and your way of presenting example code.
    I will look into it.

  • Pingback: ★ JavaScript et abstraction Actualités()

  • Bliss is the name of a Javascript template library

  • Rylan Cates

    I just want to say – I really appreciate and identify with your views on JavaScript. I tend to prefer the minimalist approach when it comes to development – especially with small projects. Oftentimes I feel like it’s easy to get dazed when trying to find what – out of all these libraries (and everything they want you to know they can do) – is relevant to me getting something done.

    I really like the approach with your documentation as I admit that I’m stubborn and am sometimes independent just to be independent. Having more information as to why I should use the library method as opposed to my own method of accomplishing something is very intriguing to me. I too have found vanilla JavaScript a touch tedious, and am so looking forward to trying out BlissJS on my current pet project.

    Thanks for sharing your years of hard work with us! I’ll be sure to drop some feedback when I get started with it.

  • Pingback: JAVASCRIPT WEEKLY NO.262 | ENUE()

  • Pingback: Дайджест интересных материалов из мира веб-разработки и IT за последнюю неделю №188 (1 — 6 декабря 2015) | Sweb – інтернет маркетинг, веб – сай()

  • steve

    You said, you don’t like large wrapper libraries but you think the frameworks are acceptable?

    Angular – is huge.

    React – reinvents dom manipulation.
    and you’re having a go at jquery?

    Some technologies are just so well documented, much easier to understand, more consistent, than others so are cheaper to build with. Jquery allows you to write in a vanilla fashion. You can easily swap back out from a jquery node to native access.

    I agree jquery is a little bigger than it needs to be. I see you are good at javascript though, and you are essentially re-writing a similar selector engine, but I’d advise using the same concepts that have become so popular with jquery like addClass, closest, html etc…because why re-write the documentation? Why challenge what is already so well known across the industry?

    • Proyb P

      Micro-framework are well suit for mobile apps.

      • steve

        Im not disputing the micro library. Im implying its bad practice to invent your own language if the original has already been done, is well known and easier to read.

  • Victor

    You’re awesome! There are so many good snippets on this site, love it all (almost). Just wanted you to know.

  • This kind of tool looks pretty helpful for those people who might have the idea on how to apply this on their work. Students perhaps can also learn something from this that might also be a great asset on their learning.

  • Pingback: News for Designers (314) - 50 CSS Tools, Javascript Charts, Flexbox Polyfill, Coding Etiquette()

  • Pingback: Weekly News for Designers (N.314) | Tech +()

  • Pingback: Weekly News for Designers (N.314) - Diseño Multimedia | KornukopiaDiseño Multimedia | Kornukopia()

  • looks very interesting!! 🙂

  • -e

    You did with JS what they should have done a long time ago. Very impressive!

  • surunzi

    I hate using big libraries for small projects too. However, instead of making a smaller one, I built a tool that scans code to generate utility libraries using small code pieces. It really reduced my pain using plain Vanilla JS, you might be interested in that:

  • Can this be used via node? i.e. package via webpack etc etc

  • Martin Flodin

    I didn’t remember the name of this library, so I went to your projects page and was a bit surprised when I didn’t find it there. Luckily I found this post, but perhaps you could add it to the projects page for others looking for it. =)

  • Cirir

    Many people can surely use this information as their guide on how are they going to use that certain tool in programming. It’s a good job that you have learned this kind of thing and shared it to the public.

  • Sean Paul

    I genuinely appreciated understanding it. Sitting tight for some more incredible articles like this from you in the nearing days Finance Dissertation Writing Service

  • Pingback: Google()

  • Pingback: prueba esto()

  • Pingback: Car care()

  • Pingback: legit work from home companies()

  • Pingback: porn()

  • Master Newton

    Question on the syntax for creating nested elements. Wouldn’t it be easier to just
    element.innerHTML = `Moose

    cat said yolo



  • Pingback: hot movies()

  • Pingback: T-shirts Factory()

  • Pingback: IT Support()

  • Pingback: 100% scam()

  • Pingback: Finger Vibrator()

  • Pingback: Cracked glass()

  • Pingback: discount sex toys()