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

trends

AI Is Coming: A Look at What's Ahead and Its Implications

The AI era has dawned, and the impact of this technology is beginning to be felt in the online adult industry. We are already seeing a plethora of content, synthetic interactions and customizable avatars enabled by artificial intelligence.

Alejandro Freixes ·
opinion

Navigating Fraud Prevention in Credit Card Transactions

In the digital age, credit card transactions are essential to global commerce, providing unmatched convenience for consumers and businesses alike. With this convenience, however, comes the risk of credit card fraud, which can result in considerable financial losses and harm brand reputation.

Jonathan Corona ·
opinion

A Guide to Avoiding Scams in Hard Link Media Buying

‘If it sounds too good to be true, it probably is.” So cautionary wisdom reminds us, yet people still get scammed all the time. Fortunately, there are “red flags” you can watch for to help you identify scams and thereby avoid them.

Juicy Jay ·
opinion

The Dos and Don'ts of AI-Generated Content

AI is a hot topic. From automation to personal assistance to content generation, AI technology is already impacting our daily lives. Many industries, including adult, have had positive results using AI for customer support and marketing.

Cathy Beardsley ·
opinion

Strategic Upscaling of Non-4K Content

If content is king in adult, then technical quality is the throne upon which it sits. Technical quality drives customer acquisition and new sales, while cementing retention and long-term loyalty.

Brad Mitchell ·
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 ·
Show More