Skip to main content

Introduction

Learn about fast-url – a high-performance URL building library that makes constructing URLs safe and convenient
3 min read

fast-url is a lightweight, high-performance JavaScript/TypeScript library for building URLs safely and conveniently. It's a modern fork of urlcat with a strong focus on performance optimization and code simplicity.

Note

Why fast-url?

Building URLs manually is error-prone and tedious. fast-url handles parameter escaping, proper URL segment joining, and clean separation of path and query parameters automatically.

Why This Fork Was Created#

The original urlcat library is a solid foundation for URL building, but over time it has faced several challenges:

Problems with the Original Project#

  • 🐌 Performance bottlenecks: The original implementation wasn't optimized for high-throughput scenarios
  • 📦 Outdated dependencies: Not regularly updated with the latest Node.js optimizations
  • 🔧 Maintenance gaps: Infrequent updates and slower adoption of modern JavaScript features
  • ⚡ Query string encoding: Used older, less efficient encoding methods

How fast-url Addresses These Issues#

fast-url was created to solve these problems while maintaining compatibility:

  1. Performance-first approach:

    • Optimized query string encoding matching Node.js performance
    • Reduced function call overhead
    • Direct constant access for better V8 JIT optimization
    • 5-20% faster than previous implementations in many scenarios
  2. Regular maintenance:

    • Active development and quick bug fixes
    • Regular dependency updates
    • Modern TypeScript implementation
  3. Simplified codebase:

    • Minimal dependencies (only fast-querystring)
    • Clean, maintainable code
    • Focus on core functionality
  4. Production-ready:

    • Comprehensive test coverage
    • Battle-tested in real-world applications
    • Performance benchmarks with CodSpeed integration

Key Features#

Lightweight

Only one dependency (fast-querystring) with minimal bundle size - perfect for performance-critical applications

Type Safe

Written in TypeScript with full type definitions for better development experience and compile-time safety

URL Safe

Automatically escapes parameters and handles edge cases - no more broken URLs from special characters

Unicode-aware

Uses codePointAt for proper Unicode handling, including graceful encoding of lone surrogates and emojis

Flexible

Multiple ways to build URLs for different use cases - from simple concatenation to complex path and query parameters

High Performance

Optimized for speed with benchmarks showing significant improvements over the original implementation

The Problem#

Building URLs manually is error-prone and difficult to maintain:

Issues with manual URL building:

  • 🔴 Double slashes when joining paths
  • 🔴 Unescaped parameters breaking URLs
  • 🔴 Complex string concatenation logic
  • 🔴 No validation of parameter types
  • 🔴 Difficult to maintain and read

The Solution#

fast-url provides a clean, safe API for URL construction:

Benefits:

  • ✅ Automatic parameter escaping
  • ✅ Proper URL segment joining
  • ✅ Clean separation of path and query parameters
  • ✅ Type checking for path parameters
  • ✅ Easy to read and maintain
Check

Performance Matters

In performance benchmarks, fast-url matches or exceeds the original urlcat implementation while providing additional safety features and better Unicode handling.

Visual Example#

Here's a visual representation of how fast-url simplifies URL building:

When to Use fast-url#

fast-url is ideal for:

  • 🌐 REST API clients: Building dynamic API endpoints
  • 🔗 URL generators: Creating shareable links with query parameters
  • 📱 Single-page applications: Managing client-side routing and navigation
  • 🛠️ Backend services: Constructing URLs for external API calls
  • 📊 Analytics tracking: Building tracking URLs with parameters

Quick Example#

Here's a real-world example showing how fast-url simplifies URL building: