DEV Community

Victor Basumatary
Victor Basumatary

Posted on

Do You Really Need JavaScript?

There's a new JavaScript library/framework released everyday and your node_modules/ directory is only becoming more denser than a black hole, but do you really need that JavaScript running in your website? Do you need JavaScript at all?

The examples that I am going to show you in this article were valid as of 21 April 2020 (Indian Standard Time).

1. swiggy.com and google.com

Swiggy is a food delivery company and application here in India. Here's how the application works with JavaScript enabled.

Selecting a delivery location in swiggy.com.

Selecting a nearby restaurant in swiggy.com.

There's a giant textbox where you enter your location. You are then presented with a list of locations that Swiggy delivers to near you. After selecting an appropriate location you are redirected to a page with a list of restaurants that service the selected location.

Here's what happens when JavaScript is disabled.

swiggy.com cannot suggest delivery locations with JavaScript disabled.

You still get the same page as we did with JavaScript enabled but this time Swiggy cannot provide you with a list of suggested delivery locations. Furthermore, you cannot progress further in the app. I'm left hungry if I have JavaScript disabled.

Let's now take a look at how we use Google with JavaScript enabled.

Searching for the term "software engineering" on google.com

Search results of the term "software engineering" on google.com

We've all used Google right? Now let's see how Google behaves with JavaScript disabled.

Searching for the term "software engineering" on google.com

Search results of the term "software engineering" on google.com

We can still get search results with JavaScript disabled. You may have noticed that Google could not provide you with autocomplete suggestions.

Observations

Google used JavaScript to enhance the experience of searching, with autocomplete suggestions and a better UI, among other things. The core feature of Google - searching - does not depend on whether we have JavaScript enabled or not.

Swiggy relies on JavaScript for its core feature - searching for restaurants around you - and so fails to work when JavaScript is disabled. Does Swiggy really need JavaScript to provide that feature to you? In my opinion, no. On the home page you need to enter a delivery location. This delivery location can be sent to the backend application which can use this along with other information like the IP address to find a list of areas that the customer might be in. The application selects the best choice and presents restaurants around that area along with the other possible locations in case the customer is elsewhere and the application made a mistake.

2. angular.io and reactjs.org

Both Angular and React are used to build Single Page Applications and if you're like me, you keep their documentation open at all times when using them. Here's Angular's and React's websites with JavaScript enabled.

angular.io with JavaScript enabled.

reactjs.org with JavaScript enabled.

And here they are with JavaScript disabled.

angular.io with JavaScript disabled.

reactjs.org with JavaScript disabled.

Angular's website only says "This website requires JavaScript" when JavaScript is disabled.

Observations.

Do you really need JavaScript to read some documentation? No. angular.io is completely unusable when JavaScript is disabled.

reactjs.org will do a full page reload when you have JavaScript disabled, otherwise it won't. I'm pretty sure there are other features missing in the website with JavaScript disabled but this is the most glaring one to me. Again, JavaScript was used to only enhance the experience of the user.

Final Words

You don't need JavaScript, for a majority of the applications out there, to deliver the core feature(s) of your application/website. Websites should be built with the assumption that JavaScript is unavailable. If JavaScript is used, it should be used to enhance the user's experience. The experience should not depend on JavaScript being available.

Why Should I Care

Your user may not be able to run JavaScript for a variety of reasons:

  • The user agent may fail to download the JavaScript after downloading the HTML
  • The user may have disabled JavaScript
  • The user agent may not support JavaScript
  • The user agent may not support the version of JavaScript you used
  • And a host of other things

Top comments (3)

Collapse
 
vlence profile image
Victor Basumatary

Update 2023: With the help of libraries like htmx and alpine you can implement most modern ui patterns while also gracefully degrading the application in case JavaScript is unavailable.

Collapse
 
jagrati639 profile image
jagrati639

I have a question out of curiosity. Say theoretically speaking, we wanted to implement Google's auto suggestion without javascript. Is it technically possible however inefficient it is??. Like on pressing a character on search box, the browser can send again request to server and server could send back the new page's html content with suggestions list. Is it theoretically possible when say for a minute we are not concerned about efficiency.

-- Thanks

Collapse
 
vlence profile image
Victor Basumatary • Edited

Hi thanks for reading the article and leaving a question. Sorry couldn't get back to you earlier.

Short answer is I don't know, maybe. I've never tried making an auto suggestion feature without JavaScript :D

The point I was making in the article is that you shouldn't build your entire application in JavaScript IF the core features can be implemented without it because otherwise you'll be left with a completely unusable application if JavaScript is unavailable, like in the examples I gave. I think we will both agree that a website which has only the core features working is far better than a wallpaper.

Let's consider your hypothetical scenario. Can we build an auto suggestion feature without JavaScript? Maybe but I don't think it's worth the effort. The core feature of the Google homepage is that you can search, not the auto suggestion. The auto suggestion is nice to have but we can live without it.

Hope that helps.