Many JavaScript applications depend on libraries that provide features developers could already use through the browser. A project might install a date library to format dates, an HTTP client to send API requests, a utility package to work with arrays, and another library to detect when elements become visible on the screen.
There is nothing wrong with using these libraries. They often make development easier and provide useful features. The problem starts when an application depends on several large packages for tasks that the browser can handle directly.
I have seen this pattern in many types of JavaScript projects. A library is introduced to solve one problem, and it stays in the application even after the original requirement changes. Developers add more packages over time without checking whether the same work can be done with existing browser features.
Modern browsers provide built-in APIs for many common tasks. JavaScript developers can use these APIs to handle dates, numbers, HTTP requests, URL parameters, element visibility, clipboard operations, and animations without always installing another package.
This does not mean every external library should be removed. A good engineering decision depends on the features the application needs, the browsers it supports, and the amount of code the team would have to maintain.
Let's look at practical examples of replacing common JavaScript libraries with native browser features.
Why Developers Should Review Their JavaScript Dependencies
A JavaScript library can save development time, but every additional package becomes part of the application's dependency tree. It may also bring its own dependencies, configuration, updates, and security considerations.
Imagine an application that uses one library only to format dates, another to create query strings, and a third to make basic HTTP requests. Each library may be useful, but the application could already have access to suitable browser APIs for these tasks.
The issue becomes more noticeable when the application grows. Developers need to update packages, check compatibility, investigate security alerts, and understand how different libraries work together. Some packages may also increase the amount of JavaScript that the browser needs to download and process.
Before adding a new package, ask a simple question: does the browser already provide the feature we need?
This question can help teams avoid unnecessary dependencies without making development more difficult.
Replace Date Libraries With the Intl API
Date formatting is a common reason developers add external JavaScript packages. Libraries such as Moment.js and other date utilities provide convenient methods for displaying dates in different formats.
However, many applications only need to display a date or time in a particular language or region. The browser already provides the Intl API for this purpose.
For example, consider an application that receives a date from an API:
const orderDate = new Date("2026-11-24T10:30:00Z");
const formattedDate = new Intl.DateTimeFormat("en-IN", {
day: "2-digit",
month: "long",
year: "numeric"
}).format(orderDate);
console.log(formattedDate);
The output is formatted according to the selected locale. In this example, the application uses Indian English formatting.
The useful part is that developers do not need to manually build the date string or maintain separate formatting rules for every region.
Format dates for different regions
An application used by customers in different countries may need to display the same date in different formats.
The Intl API makes this straightforward:
const date = new Date("2026-11-24T10:30:00Z");
const indiaDate = new Intl.DateTimeFormat("en-IN", {
dateStyle: "long"
}).format(date);
const usDate = new Intl.DateTimeFormat("en-US", {
dateStyle: "long"
}).format(date);
const ukDate = new Intl.DateTimeFormat("en-GB", {
dateStyle: "long"
}).format(date);
console.log(indiaDate);
console.log(usDate);
console.log(ukDate);
The browser applies the formatting rules for each locale. This is useful when an application serves users in multiple countries and should display dates in a familiar format.
The same API can format currency values:
const amount = 12500.75;
const indiaCurrency = new Intl.NumberFormat("en-IN", {
style: "currency",
currency: "INR"
}).format(amount);
const usCurrency = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD"
}).format(amount);
console.log(indiaCurrency);
console.log(usCurrency);
This is often enough for dashboards, shopping applications, reports, and account pages.
However, formatting and date calculations are different tasks. If an application needs complex calendar operations, recurring events, time-zone conversions, or advanced date calculations, a dedicated date library may still be useful.
Replace Query String Libraries With URLSearchParams
Applications frequently need to read and update query parameters.
For example, an e-commerce application may use a URL like this:
https://example.com/products?category=mobile&page=2&sort=price
A developer may install a query string library to read these values or create a new URL. For simple query parameter operations, the browser already provides URLSearchParams.
Consider the following example:
const params = new URLSearchParams(window.location.search);
const category = params.get("category");
const page = params.get("page");
const sort = params.get("sort");
console.log(category);
console.log(page);
console.log(sort);
The code reads the query parameters without manually splitting the URL or writing regular expressions.
Update query parameters
Suppose a user changes the sorting option on a product page. The application needs to update the URL while keeping the existing category and page values.
You can do this with the URL API:
const url = new URL(window.location.href);
url.searchParams.set("sort", "rating");
url.searchParams.set("page", "1");
window.history.replaceState({}, "", url);
console.log(url.toString());
The URL object handles the query string and its encoding.
This approach is useful for search pages, filters, pagination, and applications where users should be able to share a link containing the current page state.
For more advanced query serialization, nested objects, or custom array formats, a dedicated library may still be the better choice. URLSearchParams handles standard query parameters, not every query string format used by JavaScript applications.
Replace Basic HTTP Client Usage With Fetch API
Many applications use Axios or another HTTP client to communicate with backend APIs.
These libraries provide useful features, including request and response interceptors, automatic JSON handling, and convenient error handling. However, developers sometimes use them only to send a GET or POST request.
The browser provides the Fetch API for making HTTP requests.
A simple GET request looks like this:
async function getUsers() {
const response = await fetch("/api/users");
if (!response.ok) {
throw new Error(`Request failed: ${response.status}`);
}
return await response.json();
}
getUsers()
.then(users => console.log(users))
.catch(error => console.error(error));
One important difference is that fetch does not reject its promise just because the server returns an HTTP error status such as 404 or 500.
The application must check response.ok or response.status and handle the result.
This is an important detail when replacing an HTTP client. A direct replacement that ignores HTTP status codes can introduce bugs that were previously handled by the library.
Send data using POST
The Fetch API also supports POST requests:
async function createUser(user) {
const response = await fetch("/api/users", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(user)
});
if (!response.ok) {
throw new Error(`Unable to create user: ${response.status}`);
}
return await response.json();
}
const newUser = {
name: "Vijay",
email: "[email protected]"
};
createUser(newUser)
.then(result => console.log(result))
.catch(error => console.error(error));
The browser sends the request and returns a response that the application can process.
For a small application, this may be all that is required.
Handle request timeouts
A production application should also consider requests that take too long to complete.
The browser provides AbortSignal.timeout() to create a signal that automatically aborts an operation after a specified time:
async function getProducts() {
const response = await fetch("/api/products", {
signal: AbortSignal.timeout(10000)
});
if (!response.ok) {
throw new Error(`Request failed: ${response.status}`);
}
return await response.json();
}
In this example, the request is given a timeout of ten seconds.
The application should still handle the resulting error because a timeout, network failure, or server error can interrupt the request.
If the application needs shared authentication handling, request interceptors, automatic token refresh, advanced retry policies, or consistent request behavior across many services, keeping an HTTP client library may be more practical.
The important point is to avoid adding a large dependency when the application only needs a few basic requests.
Replace Scroll Detection Libraries With IntersectionObserver
Another common use of JavaScript libraries is detecting when an element becomes visible on the screen.
This feature is useful for lazy loading, infinite scrolling, loading images, and starting animations when users reach a particular section of a page.
Some older implementations attach scroll event listeners and repeatedly calculate element positions. This can create unnecessary work, especially when several elements need to be monitored.
The browser provides IntersectionObserver for this purpose.
For example, suppose an application displays a large list of articles and wants to load additional content when the user reaches the bottom.
Add a marker at the end of the list:
<div id="article-list">
<!-- Article items -->
</div>
<div id="load-more-marker"></div>
Now observe the marker:
const marker = document.querySelector("#load-more-marker");
const observer = new IntersectionObserver((entries) => {
for (const entry of entries) {
if (entry.isIntersecting) {
loadMoreArticles();
}
}
});
observer.observe(marker);
When the marker enters the observer's visible area, the callback runs.
The application can then load more articles from the backend.
Stop observing when the work is complete
An observer should not continue monitoring elements when the application no longer needs it.
For example:
const marker = document.querySelector("#load-more-marker");
const observer = new IntersectionObserver(async (entries) => {
const entry = entries[0];
if (!entry.isIntersecting) {
return;
}
observer.unobserve(marker);
try {
await loadMoreArticles();
} finally {
observer.observe(marker);
}
});
observer.observe(marker);
This example temporarily stops observing the marker while the request is running. It then starts observing again after the request completes.
A real application should also maintain a loading flag and check whether more data is available. Otherwise, repeated visibility changes could trigger unnecessary requests.
IntersectionObserver is a good replacement for many visibility detection libraries. It is not intended for every possible scroll calculation. If an application needs exact pixel-level movement or detailed scroll animation control, another solution may be required.
Replace Element Size Detection Libraries With ResizeObserver
Responsive layouts often need to react when an individual component changes size.
For example, a dashboard card may display a chart. The chart needs to adjust when the card becomes narrower, even if the browser window itself has not changed size.
Listening only to the window resize event is not enough because an element can change size for many reasons, including changes to its parent layout, sidebar visibility, or surrounding content.
The browser provides ResizeObserver to monitor changes in an element's dimensions.
Consider the following HTML:
<div id="dashboard-card">
<h2>Sales Overview</h2>
<p id="card-width"></p>
</div>
You can observe the card like this:
const card = document.querySelector("#dashboard-card");
const widthLabel = document.querySelector("#card-width");
const resizeObserver = new ResizeObserver((entries) => {
for (const entry of entries) {
const width = entry.contentRect.width;
widthLabel.textContent = `Card width: ${Math.round(width)}px`;
if (width < 400) {
card.classList.add("compact");
} else {
card.classList.remove("compact");
}
}
});
resizeObserver.observe(card);
The callback runs when the observed element's size changes.
This makes it useful for dashboards, reusable components, charts, side panels, and other layouts where the component needs to respond to its own available space.
Remember to disconnect the observer when the component is removed or when the observation is no longer required. This is especially important in applications that create and destroy components frequently.
Replace Clipboard Libraries With the Clipboard API
Many applications allow users to copy information such as order numbers, invitation links, API examples, or account identifiers.
A separate clipboard library is not always necessary for this feature. Modern browsers provide the Clipboard API for reading and writing clipboard content.
For example, a button can copy an invitation link:
<button id="copy-button">Copy Invitation Link</button>
The JavaScript implementation can use navigator.clipboard.writeText():
const copyButton = document.querySelector("#copy-button");
copyButton.addEventListener("click", async () => {
const invitationLink = "https://example.com/invite/12345";
try {
await navigator.clipboard.writeText(invitationLink);
copyButton.textContent = "Copied";
} catch (error) {
console.error("Unable to copy text:", error);
}
});
The browser handles the clipboard operation.
There are a few important conditions to remember. Clipboard access generally requires a secure context, such as HTTPS, and browsers may require the operation to happen as a result of a user action. Permission and browser behavior can also differ.
For applications that only need to copy text, the native API is usually a straightforward choice. More advanced clipboard operations, such as working with several content types or older browser support, may require additional handling.
Replace Basic Animation Libraries With CSS and Web Animations API
JavaScript animation libraries are useful for complex movement, timelines, and coordinated transitions.
However, many applications only need simple visual effects such as fading an element, moving a notification, or showing a menu.
CSS transitions can handle many of these tasks without additional JavaScript dependencies.
For example:
.notification {
opacity: 0;
transform: translateY(15px);
transition: opacity 300ms ease, transform 300ms ease;
}
.notification.visible {
opacity: 1;
transform: translateY(0);
}
JavaScript only needs to add or remove a class:
const notification = document.querySelector(".notification");
notification.classList.add("visible");
The browser applies the transition when the class changes.
Use the Web Animations API for JavaScript-controlled animations
Sometimes the application needs more control over an animation.
The Web Animations API provides a browser-native way to create and control animations:
const notification = document.querySelector(".notification");
const animation = notification.animate(
[
{
opacity: 0,
transform: "translateY(15px)"
},
{
opacity: 1,
transform: "translateY(0)"
}
],
{
duration: 300,
easing: "ease-out",
fill: "forwards"
}
);
The animate method returns an Animation object that can be controlled from JavaScript.
For example, the application can wait for the animation to finish:
animation.finished.then(() => {
console.log("Animation completed");
});
This is useful for notifications, menus, simple page elements, and small interface interactions.
For complex animation timelines, advanced gestures, physics-based movement, or large coordinated animations, a dedicated animation library may still provide a better development experience.
A Practical Comparison of Common Replacements
The following table shows some common library use cases and the browser features that may replace them.
Common requirement | Library often used | Native browser feature |
|---|
Date and number formatting | Moment.js, formatting utilities | Intl API |
Query parameter handling | Query string libraries | URL and URLSearchParams |
Basic HTTP requests | Axios | Fetch API |
Element visibility detection | Scroll and visibility libraries | IntersectionObserver |
Element size monitoring | Resize utilities | ResizeObserver |
Copying text | Clipboard libraries | Clipboard API |
Simple animations | JavaScript animation packages | CSS transitions and Web Animations API |
Basic array operations | Utility libraries | Array methods such as map, filter, and reduce |
These are possible replacements, not automatic one-to-one migrations. A library may provide extra features that the native API does not support.
The right decision depends on what the application actually uses.
When You Should Keep an External JavaScript Library
Replacing every dependency with browser APIs is not a good engineering goal.
A native API is useful when it solves the requirement clearly and does not create additional maintenance work. However, some libraries provide functionality that would take considerable time to implement correctly.
For example, a date library may support complex time-zone calculations, calendar systems, recurring schedules, and date arithmetic. Rebuilding these features with basic browser APIs may create more problems than it solves.
An HTTP client may provide request interceptors, retry policies, centralized error handling, and authentication support that are used throughout a large application.
An animation library may provide a complete timeline system that is difficult to reproduce with individual CSS transitions.
Before removing a package, compare the features the application currently uses with what the native API provides.
Consider these questions:
Does the browser API cover all the required features?
Does the application need to support older browsers?
Will replacing the library introduce more custom code?
Does the library provide important behavior that the native API does not?
Will the team be able to maintain the replacement easily?
Sometimes keeping a small, well-maintained library is the simpler and safer decision.
How to Migrate Without Breaking the Application
Removing a dependency should be treated as a code change, not just a package cleanup operation.
Start by identifying exactly where the package is used. A package may be imported in several components, services, or configuration files.
Next, identify the features the application actually needs. Do not replace an entire library if the application only uses one small part of it.
For example, if an application uses a date library only to format dates, replace those formatting calls with Intl.DateTimeFormat. There is no need to rewrite unrelated date calculations at the same time.
After updating the code, test the affected functionality.
For a date replacement, check different locales, invalid dates, and time-zone behavior. For an HTTP replacement, check unsuccessful responses, network failures, request cancellation, and authentication. For a clipboard replacement, test secure-context requirements and browser permissions.
Once the new implementation works, remove the old package using the project's package manager:
npm uninstall moment
Then run the project's tests and production build:
npm test
npm run build
Finally, inspect the package-lock.json file and confirm that the removed package is no longer required by the application. It may still remain as a transitive dependency if another package uses it.
For a larger application, make one replacement at a time. This makes it easier to find the cause if a feature stops working.
Best Practices for Reducing Unnecessary JavaScript Libraries
A healthy JavaScript project does not need to avoid every external dependency. It needs to use dependencies for the right reasons.
Before installing a package, check whether the browser already provides a suitable API. If the native feature is clear, well supported by the browsers your application targets, and easy for your team to maintain, it may be the better choice.
Also, review existing dependencies during regular maintenance. Look for packages that are used only for simple formatting, basic URL handling, or small DOM operations.
Do not replace a library just to reduce the dependency count. If the native implementation requires hundreds of lines of custom code to reproduce a feature that a maintained library already handles well, the migration may not be worth it.
Check browser support before adopting a native API. MDN provides compatibility information for browser features, but your own application should define which browsers and versions it needs to support.
Keep the implementation focused. A small wrapper around a native API can make the code easier to use across the application without introducing another package.
Conclusion
JavaScript developers have more browser-native features available than they may realize. Tasks such as formatting dates, handling query parameters, sending HTTP requests, observing element visibility, monitoring component sizes, copying text, and creating simple animations can often be handled without installing additional libraries.
The main benefit is not simply having fewer packages. It is reducing unnecessary code and making the application easier to understand and maintain.
However, native browser APIs are not replacements for every library. Complex date calculations, advanced HTTP workflows, and detailed animation systems may still need dedicated packages.
The best approach is to review dependencies based on actual usage. Keep libraries that provide real value, and use native browser features when they solve the problem clearly. This gives the application a simpler dependency tree without making the code harder to maintain.
Join the conversation! Your thoughts help the community grow.