5 Reasons You Don’t Always Need a JavaScript Framework
Frameworks are great tools to help relieve developers of having to constantly reinvent the wheel and rewrite code. When a project needs to be deployed efficiently and effectively, a framework will go a long way to helping your developer team make it happen.
But not every project needs a framework. This is true for many of the languages your software engineers depend on. Does this hold true for JavaScript? You bet.
JavaScript frameworks are often considered essential tools for modern frontend web development. By employing any one of the numerous frameworks, your developers can build scalable, dynamic web-based applications that can be used within your company — or even by consumers, customers, or clients. There are quite a number of frameworks to choose from, such as Vue.js, Angular, Svelte, Express.js, Bootstrap, and Django.
So, when you need a framework, they’re there for the taking (and most are open source, so they’re free to use). But when might you not need a JavaScript framework? Let’s take a look at five reasons.
1. If What You’re Working on Is Simple
Truth be told, JavaScript frameworks are best used on more complicated projects for applications at scale. If you’re working on something simple and small, then a framework is going to be overkill. In fact, if you’re working on a smaller project, a framework will only complicate matters, so you’re better off doing without.
Remember, the point of using a framework is to simplify your work and save time, by implementing everything you need from vanilla JavaScript. If the project you’re working on is smaller, the time you save will be overshadowed by the time you spend either getting up to speed on the framework, or adding it into the mix.
If the goal of the project is to keep it simple, don’t bother with a framework.
2. When HTML and CSS Alone Will Do the Trick
Most of what you’ll be doing with a JavaScript framework is building web applications. Yes, JavaScript can help make those applications become more interactive, dynamic and exciting, but there are times when JavaScript is overkill and will slow down the performance of the site.
Step back and think about this: Are HTML and CSS enough to build the website or web application? If so, then stick with the basics. Sure, you might need to add some JavaScript into the mix, but adding a framework into that process could very quickly muddy the clearer waters created by more fundamental languages. Remember this: HTML is for structure, CSS is for appearance, and JavaScript is for behavior. HTML and CSS are often crucial ingredients, whereas JavaScript is the icing on the cake. A JavaScript framework is a tool that helps you mix all of those ingredients together to bake a cake worthy of competition but adds a layer of complication you might not need… especially when you only want a basic cake.
3. If You’re Using JavaScript ES6
With the release of JavaScript ES6, the necessity for frameworks isn’t nearly as great as it once was. And with the inclusion of modules and classes with ES6, most of the popular frameworks could be thought of as obsolete.
Remember, frameworks are used to abstract some of the more complex aspects of development. With the release of ES6, a number of new features (such as default parameters, template literals, multi-line strings, destructuring assignment, enhanced object literals, and arrow functions — along with modules and classes), reduces the need to even bother with frameworks for many use cases.
Prior to ES6, working with things like classes was a major challenge, even though previous iterations were designed to specifically support classes.
These new features of JavaScript go a long way towards making frameworks a thing of the past, because they bring certain functionalities to the language that were previously unavailable. Instead of having to employ those third-party tools, most everything will be pre-packaged within the language itself.
4. If Creative Freedom Is Your Jam
Let’s face it, when you employ a JavaScript framework, you typically can only use one and you’re limited to the constraints of that framework. When you don’t use a framework, you can style your web development exactly how you want. And given you can do just about anything you want with the combination of HTML, CSS and JavaScript, unless you’re building at scale and don’t care about creative freedom, you already have everything you need and the sky’s the limit for your creativity.
5. HTMX
HTMX is the successor to intercooler.js (which uses familiar, declarative HTML attributes to add AJAX to an application). This new library allows you to access many modern browser features (such as AJAX, CSS Transitions, WebSockets, and Server-Sent Events) directly from HTML, in place of using JavaScript. This means developers will be able to build modern interfaces without having to resort to JavaScript — and, by extension, JavaScript frameworks.
From the official HTMX website, we see this example:
1 2 3 4 5 6 |
<button hx-post="/clicked" hx-trigger="click" hx-target="#parent-div" hx-swap="outerHTML"> Click Me! </button> |
In this example, when a user clicks a button, an HTTP POST request is issued to /clicked, and then the response is used to replace the element using the parent-div from within the DOM.
Conclusion
Two of the main reasons for using a framework are speed and the integration of external data sources. If neither of those is an issue with your project, then a framework is only going to get in your way and squash your creativity.
JavaScript frameworks certainly have their purposes and shouldn’t automatically be brushed aside. But if you have the time and inclination, building directly with HTML, CSS and JavaScript code can be very rewarding.