blog.openreplay.com

Things to Stop Doing in JavaScript in 2025 - OpenReplay Blog

12/12/2025Updated 4/4/2026

Excerpt

JavaScript moves fast. Code patterns that felt modern three years ago now ship unnecessary bytes, ignore platform improvements, or rely on deprecated APIs. If you’re building production web apps in 2025, here are the JavaScript anti-patterns to avoid—and what to reach for instead. ## Key Takeaways - Deprecated features like `with` statements, `__proto__`, and `String.prototype.substr` should be replaced with modern alternatives. - Legacy libraries such as jQuery, Moment.js, and Lodash can often be replaced with native browser APIs and ES2023–ES2025 features. - Modern CSS now handles many tasks that previously required JavaScript, including container queries, the `:has()` selector, and scroll-linked animations. … - **`with` statements** — Banned in strict mode since ES5. They create ambiguous scope and break optimizations. - **`__proto__`** — Use `Object.getPrototypeOf()` and `Object.setPrototypeOf()` instead. - **`String.prototype.substr`** — Deprecated. Use `slice()` or `substring()`. - **Legacy RegExp statics** like `RegExp.$1` — These are non-standard and unreliable across engines. These aren’t edge cases. Linters flag them for good reason. Modern JavaScript patterns assume you’ve moved on. ## Stop Reaching for Legacy Libraries by Default jQuery, Moment.js, Lodash, and RequireJS solved real problems—in 2015. Today, the platform covers most of their use cases natively. **What to do instead:** - **DOM manipulation** — `querySelector`, `querySelectorAll`, and modern DOM APIs handle what jQuery once did. - **Date handling** — The Temporal API is coming. Until full support lands, use date-fns or native `Intl.DateTimeFormat`. - **Utility functions** — ES2023–ES2025 features like `Object.groupBy()`, new Set methods (`.union()`, `.intersection()`), and iterator helpers (`.map()`, `.filter()` on iterators) replace most Lodash imports. - **Module loading** — Native ESM and `import()` make RequireJS and AMD obsolete. Shipping a 30KB library for functionality the browser provides free is a frontend mistake to stop in 2025. … - **`RegExp.escape()`** — Safely escape strings for regex patterns. - **Import attributes and JSON modules** — `import data from './config.json' with { type: 'json' }`. - **Top-level `await`** — Use it in modules without wrapping everything in async IIFEs. … ## Stop Using JavaScript for What CSS Now Handles Modern CSS has absorbed functionality that once required JavaScript. Using JS for these creates unnecessary complexity and hurts performance. **Let CSS handle:** - **Container queries** — Responsive components without `ResizeObserver` hacks. - **`:has()` selector** — Parent selection without DOM traversal. - **Scroll-linked animations** — `animation-timeline: scroll()` replaces scroll event listeners. - **View transitions** — Native page transition effects. … ## Stop Using Mutation Events and Third-Party Cookie Assumptions **Mutation Events** (`DOMSubtreeModified`, `DOMNodeInserted`) are deprecated and perform poorly. Use `MutationObserver` instead—it’s been stable for over a decade. **Third-party cookies** are effectively dead for tracking and cross-site auth flows. Chrome’s deprecation timeline has shifted, but Safari and Firefox blocked them years ago. Build authentication flows with first-party cookies, tokens, or federated identity. Don’t architect around assumptions that break in half your users’ browsers. ## Stop Starting New Projects with CommonJS If you’re writing browser code in 2025 and reaching for `require()` or heavy webpack configurations, pause. Native ESM works everywhere that matters. Lighter bundlers like Vite and esbuild handle the remaining edge cases with minimal configuration. CommonJS still has its place in Node.js libraries targeting older environments. For new frontend code, it’s legacy baggage. ## Conclusion JavaScript best practices in 2025 aren’t about chasing trends—they’re about recognizing when the platform has caught up to your dependencies. Every deprecated feature you remove, every unnecessary library you drop, and every CSS-native solution you adopt makes your code smaller, faster, and easier to maintain. Audit your current projects. Check your imports. Question whether that utility function needs a library or just a native method you haven’t learned yet. The modern JavaScript patterns are already here—you just have to use them.

Source URL

https://blog.openreplay.com/stop-doing-javascript-2025/

Related Pain Points

Third-party cookie deprecation breaking authentication architectures

8

Third-party cookies are effectively dead for tracking and cross-site authentication flows. Chrome's deprecation timeline has shifted, but Safari and Firefox blocked them years ago. Developers who architected authentication around third-party cookie assumptions now face breaking changes across browsers.

authJavaScript

Backward Compatibility Constraints and Language Baggage

5

JavaScript's long history creates technical debt through legacy patterns, older syntax, and poorly maintained libraries that still exist in many codebases. Backward compatibility requirements slow innovation, forcing the language to straddle old and new idioms simultaneously.

compatibilityJavaScriptECMAScript

Using JavaScript instead of CSS for tasks now handled natively

5

Developers continue to write JavaScript for functionality that modern CSS now handles natively, such as container queries, the `:has()` selector, scroll-linked animations, and view transitions. This creates unnecessary complexity and hurts performance.

performanceJavaScriptCSS

Deprecated Mutation Events performance and compatibility issues

4

Mutation Events (`DOMSubtreeModified`, `DOMNodeInserted`) are deprecated and perform poorly. Although `MutationObserver` has been stable for over a decade as a replacement, developers still use the older, slower APIs.

performanceJavaScript

CommonJS to ESM migration friction in new projects

4

Developers starting new browser-based projects in 2025 sometimes default to CommonJS (`require()`) and heavy webpack configurations despite native ESM working everywhere that matters. This creates unnecessary migration burden and uses legacy tooling patterns.

dxJavaScriptCommonJSESM+3