This is our sixth article in a series that introduces the latest useful and freely available tools and techniques, developed and released by active members of the Web design community. The first article covered PrefixFree1; the second introduced Foundation2, a responsive framework; the third presented Sisyphus.js3, a library for Gmail-like client-side drafts. The fourth shared a free plugin called GuideGuide4 with us, and in the fifth we’ve announced Erskine’s responsive grid generator Gridpak5.
What Is JS Bin?
JS Bin96 is one of the very first public paste bins with the output rendered live in your browser and available to share and edit with the completed output. Released back in 2008, JS Bin is now on its third iteration and after a long and thorough development finally includes some of the original features I wanted to build JS Bin with. It’s completely free to use all its features and open source, and it’s available on Github7.
In both current and previous versions, the UX has been a big part of the update. Danny Hope10 volunteered his UX experience to this open source project and collaborated very closely with me, allowing us to instantly try out UX ideas, see them in action and decide whether they worked or not.
This move to Node allows us to introduce two new useful features:
- Live remote rendering
Both techniques use EventSource and a little technique that I call The Spike.
The key difference between the old and the new JS Bin is that as you type – JS Bin is saving. Means, as soon as your first key stroke lands, you’ve got your own URL. You keep typing, it keeps saving. If you want to stop saving against that version, just create a milestone and live saving will be applied to the new revision.
/watch and they become voyeurs to your live coding. I’d love to see this live at a conference.
Live remote rendering
Ever wanted to check the output on multiple platforms: Firefox, Chrome, IE, iPads, Androids, Windows Phone, even a Boot 2 Gecko phone? Maybe all at a once? Maybe without ever hitting refresh?
JS Bin can do this. Simply point the device or browser to your full preview URL (basically removing
/edit from the URL) and any changes you make as you type will cause the target device to refresh its content.
The URL structure even has a shortcut, if you’re registered, you can always point the URL to http://jsbin.com/[username]/last12 and it’ll pull up the last bin you’ve worked on. Along with live remote rendering, I’ve been working with the Adobe Shadow team and they’ve gone ahead and built compatibility with JS Bin directly in to Shadow.
How the live stuff works
Now, that’s an interesting question! And it has a quite simple answer. A while back I tried out a comet13 PHP based version of CodeCasting which was way, way more complicated. It worked, but releasing wasn’t possible as my server couldn’t take more than just a few concurrent sessions. The move to Node years later fixes that.
As you type, the tool sends an Ajax save request (after an idle time of 200ms). On the server side, this triggers an event which says “the bin with this url has just changed”. Now, when viewing the CodeCasting URL or the live remote rendering, each user is connected to the Spike application. It listens for the event that says that a bin has changed, and when that happens, it just finds all the users watching a particular URL and sends them the updated panel (so we only send the CSS panel if the CSS panel changed).
An EventSource14 maintains a persistent connection with the server and is listening for those events in the browser. When the event is received, depending on the content type, it’ll either inject the content live, or refresh the page providing users with the latest version of the code.
Other Important Features
Some of these features were always part of JS Bin, but hidden inside of the “beta” access – which required a clunkly console command. Now JS Bin 3 adds the much needed UI to do simple things like login to remember your history of bins.
- Login to remember your history
- Your full history on a single page with live previews on hover
- An API to control default settings (useful if you’re preparing a teaching session)
- Processors, so you can use Markdown, CoffeeScript and LESS, amongst others
- CSS panel
- Console panel
- Support for more libraries (including Bootstrap, Backbone, etc)
- Native support in Adobe Shadow16 (you can point your browser to JS Bin and Adobe Shadow will render the live output automatically)
- “Edit from your editor and render remotely” feature. You’ll have to see it17 to believe it (idea and code by @wookiehangover18)
- Our badass robot mascot: Dave19, the JS Bin Bot (stickers will be made!)
Dave, the JS Bin Bot mascot, created by @yoheis (of PhoneGap fame).
Hack, Play, Share & Get Involved
I’m really excited to share this updated version of JS Bin. Watch out for the twitter account @js_bin2115 because it will be posting tips and screencasts, and do send your feedback22 with issues, ideas or just to tell us where you’re using JS Bin!
- 1 https://www.smashingmagazine.com/2011/10/12/prefixfree-break-free-from-css-prefix-hell/
- 2 https://www.smashingmagazine.com/2011/10/25/rapid-prototyping-for-any-device-with-foundation/
- 3 https://www.smashingmagazine.com/2011/12/05/sisyphus-js-client-side-drafts-and-more/
- 4 https://www.smashingmagazine.com/2012/01/03/guideguide-free-plugin-for-dealing-with-grids-in-photoshop/
- 5 https://www.smashingmagazine.com/2012/03/19/gridpak-the-responsive-grid-generator/
- 6 http://jsbin.com/
- 7 http://github.com/remy/jsbin
- 8 http://jsbin.com/
- 9 http://jsbin.com/
- 10 http://twitter.com/yandle
- 11 http://twitter.com/ac94
- 12 http://jsbin.com/rem/last
- 13 http://en.wikipedia.org/wiki/Comet_(programming)
- 14 http://html5doctor.com/server-sent-events/
- 15 http://twitter.com/js_bin
- 16 http://labs.adobe.com/technologies/shadow/
- 17 http://www.youtube.com/watch?v=mY56fNmn2cE
- 18 http://twitter.com/wookiehangover
- 19 http://twitter.com/js_bin
- 20 https://github.com/remy/jsbin/blob/master/TODO.md
- 21 http://twitter.com/js_bin
- 22 http://github.com/remy/jsbin/issues
Hold on, Tiger! Thank you for reading the article. Did you know that we also publish printed books and run friendly conferences – crafted for pros like you? Like SmashingConf Barcelona, on October 25–26, with smart design patterns and front-end techniques.