When the use of JavaScript is justified

JavaScript is a controversial topic, especially in privacy and open source circles. That’s because JavaScript is often used to execute code on website visitors’ devices that does things that aren’t so cool. For example, tracking users across the entire Internet. That’s why the use of ad blockers is actually indispensable nowadays, and some go so far as to block JavaScript altogether.

But JavaScript, if it is not used against the user, is not such a bad thing. It allows features to be implemented that would not be possible without JavaScript.

For example, I have had the feature to read aloud posts on my website for quite some time now. With just a little bit of JavaScript and the SpeechSynthesis API, this is quite easy to implement and works locally on many devices.

Today I added another feature. A link to view a translation of the post, because many people may not understand English that well, or want to read my German articles as well, without having the necessary German knowledge. And I like to make it as easy as possible for people to read my posts.

The translation feature also works with JavaScript. Without JavaScript, the translation button links to Google Translator, where the user then has to initiate a translation into the preferred language by themselves. With JavaScript, after loading the post, the link to the translation is changed and set so that the user’s language is used directly as the target language for the translation. (You can look at the source code.)

I know Google translator isn’t all that great either in terms of privacy or translation quality, but as far as I know DeepL doesn’t offer the ability to translate entire web pages yet.

Many things can be implemented without JavaScript and I am in favor of using a solution without JavaScript wherever possible, especially since they are much more resource-efficient in most cases. But for features that can offer real added value to the visitor, I think the use of JavaScript is definitely justified.

Interactions & Comments