Dev Depot: Relying on Ractive for Interactivity

Intended to help make the web interactive by default, Ractive.js (www.ractivejs.org) provides developers with next-generation DOM manipulation capabilities by changing the relationship between HTML and JavaScript.

Initially created to tackle the problems of data binding in a more elegant way, Ractive.js features expressions with dependency tracking, animations, two-way binding, SVG support and more.

This kind of surgical DOM manipulation is more efficient than constantly trashing views only to re-render them, and it scales far more elegantly than manually updating elements.

Reportedly backed by the Bill & Melinda Gates Foundation’s support for Guardian Global development, Ractive is used to create interactive journalism at guardian.co.uk, where it reportedly solves some of the biggest headaches in web development, including data binding, efficient DOM updates and event handling, with almost no learning curve.

“HTML is an amazing language for creating static documents, but it was never designed for interactive web apps,” developer Rich Harris states. “Many libraries try to get round HTML’s limitations, but very few tackle them head on.”

Ractive.js works by parsing HTML templates and then creating a lightweight internal representation of the DOM.

“Before, HTML was an inert substance that you would breathe life into,” Harris adds. “Now, it’s a blueprint for an app that’s interactive by default.”

The developers cite the example of traditional templating engines and frameworks that force users to re-render based on data changes, as one reason for using Ractive.js to overcome common limitations.

“So you have to split components up into atomic chunks — list items instead of lists, buttons instead of button panels [and] single data points instead of charts, often each with its own view class, each with its own render method,” Harris explains. “All too often, templating just means replacing one kind of spaghetti code with another!”

According to Harris, the Ractive.js script constructs a parallel DOM representation that is aware of its dependencies and when those values change, it knows exactly which parts of the real DOM need to be updated.

“This kind of surgical DOM manipulation is more efficient than constantly trashing views only to re-render them,” Harris adds. “And it scales far more elegantly than manually updating elements.”

Harris notes that Ractive.js received inspiration from several other projects, such as Knockout.js, Backbone and AngularJS, which is a popular framework by Google. He also notes that Ractive.js excels in its ease of learning, which is aided by interactive tutorials that allow users to master Ractive.js in an hour or two.

On the topic of frameworks, it is important to note that they come at a cost in size and complexity, with steep learning curves.

“Particularly for smaller projects, [frameworks are] often a case of using a sledgehammer to crack a nut,” Harris states. “What should be an incredibly basic task is a snakepit of compromises and ugly code — yet we’re all so used to developing this way that we’re barely even aware of how awkward it is.”

Ractive.js was an important development for the Guardian interactive team as it faces challenges from creating app-like experiences on the web, which require huge amounts of DOM manipulation performed under extremely tight deadlines.

While the developers acknowledge that none of this is something that can’t already be done with standard JavaScript, they say that the real power of Ractive.js is revealed when exploiting the script’s statefulness and dependency tracking — such as complex but easy-to-create animations.

“We’re one step closer to the holy grail of completely declarative, reactive programming,” Harris concludes.

Although Ractive.js is still an early-stage project, it has already seen production use in several interactives and is currently under active development. For developers seeking to stay on the cutting edge, however, it is an interesting project that is worth a closer look.

Related:  

Copyright © 2024 Adnet Media. All Rights Reserved. XBIZ is a trademark of Adnet Media.
Reproduction in whole or in part in any form or medium without express written permission is prohibited.

More Articles

profile

'Traffic Captain' Andy Wullmer Braves the High Seas as Spirited Exec

Wullmer networked and hobnobbed, gaining expertise in everything from ecommerce to SEO and traffic, making connections and over time rising through the ranks of several companies to become CEO of the mobile business arm of TrafficPartner.

Alejandro Freixes ·
opinion

To Cloud or Not to Cloud, That Is the Question

Let’s be honest. It just sounds way cooler to say your business is “in the cloud,” right? Buzzwords make everything sound chic and relevant. In fact, someone uninformed might even assume that any hosting that is not in the cloud is inferior. So what’s the truth?

Brad Mitchell ·
opinion

Upcoming Visa Price Changes to Registration, Transaction Fees

Visa is updating its fee structure. Effective April 1, both the card brand’s initial nonrefundable application fee and annual renewal fee will increase from $500 to $950. Visa is also introducing a fee of 10 cents for each settled transaction, and 10 basis points — 0.1% — on the payment volume of certain merchant accounts.

Jonathan Corona ·
opinion

Unpacking the New Digital Services Act

Do you hear the word “regulation” and get nervous? When it comes to the EU’s Digital Services Act (DSA), you shouldn’t worry. If you’re complying with the most up-to-date card brand regulations, you can breathe a sigh of relief.

Cathy Beardsley ·
opinion

The Perils of Relying on ChatGPT for Legal Advice

It surprised me how many people admitted that they had used ChatGPT or similar services either to draft legal documents or to provide legal advice. “Surprised” is probably an understatement of my reaction to learning about this, as “horrified” more accurately describes my emotional response.

Corey D. Silverstein ·
profile

WIA Profile: Holly Randall

If you’re one of the many regular listeners to Holly Randall’s celebrated podcast, you are already familiar with her charming intro spiel: “Hi, I’m Holly Randall and welcome to my podcast, ‘Holly Randall Unfiltered.’ This is the show about sex, the adult industry and the people in it.

Women In Adult ·
trends

What's Hot Now: Leading Content Players on Trending Genres, Monetization Strategies

The juggernaut creator economy hurtles along, fueled by ever-ascendant demand for personality-based authenticity and intimacy — yet any reports of the demise of the traditional paysite are greatly exaggerated.

Alejandro Freixes ·
opinion

An Ethical Approach to Global Tech Staffing

One thing my 24-year career as a technologist working to support the online adult entertainment industry has taught me about is the power of global staffing. Without a doubt, I have achieved significantly more business success as a direct result of hiring abroad.

Brad Mitchell ·
opinion

Finding the Right Payment Partner

Whenever I am talking with businesses that are just getting started, one particular question comes up a lot: “How do I get a merchant account?” It’s a simple question, but it has a complicated answer.

Jonathan Corona ·
opinion

The Taxman Cometh for Every Business

February may be the month of romance, but it is also a time when we need to think about something that inspires very little love: taxes. April is not far away, and the taxman is always waiting. This year, federal and most state income taxes are due Monday, April 15.

Cathy Beardsley ·
Show More