Backbone.js, Underscore.js and why they matter for WordPress

WordPress is transforming and you may not even know it. The project’s largely been a PHP driven framework. According to Github, the code itself is around 85% PHP and 15% JS in WordPress 3.5. In the future, JavaScript is likely to make up a majority of the project’s code. And Backbone.js and Underscore.js have a big part of that shift. We should get ready for the change, and learn how to use these new tools.

WordPress is transforming and you may not even know it. The project’s largely been a PHP driven framework. According to Github, the code itself is around 85% PHP and 15% JS in WordPress 3.5. I can’t find the reference right now, but Matt Mullenweg has commented before that based on the current pace of change, JavaScript will likely make up the majority of the code in the coming years. You may know that the new media manager in 3.5 is pretty much entirely JavaScript. The theme customizer is largely JavaScript too.

This means we’re in for a transformative time as WordPress developers. And tools like Backbone and Underscore are partially what we have to thank for that. I’m not an expert at all. I’m not even a novice. But my understanding is that JavaScript is really stretching its legs with new-ish frameworks like these that allow programmers to do much more substantial stuff in codebases, especially in terms of communicating with the server.

And using these methods, vs purely PHP, allow for the application to do things faster and offer a nice, snappy experience,  and probably loads of other benefits that perhaps Koop, Nacin, or someone smart could elaborate on. I just know I like using the new tools in WordPress built this way. I also know that there are a lot of outdated plugins that haven’t updated from instantiating thickbox media modals to the new media modal. And that is in part because of the lack of developers’ experience with the tools.

It’s time for me to stop, because I’m already beyond my pay grade. But if I want to stay in the game in a few years, I imagine I’ll need to change that.

So, the purpose of this post is to show you some resources for learning. Here’s a sample plugin by Thomas Griffin (Soliloquy slider author) on integrating the new media manager in a plugin. And here’s another post by Mike Jolley (lead developer of WooCommerce) showing how to use the new media manager in a plugin.

More generically, check out this post about these frameworks getting into WordPress core in 3.5. Also watch this video tutorial by Jeffrey Way on understanding Backbone and the server. And best of all peek into this Code School class on Backbone if you’re ready to get started on learning Backbone.