Skip to main content

Welcome to dldr

dldr is a lightweight, efficient utility for batching and caching operations. It automatically groups multiple requests for data within the same tick, reducing redundant operations and improving performance.
dldr uses queueMicrotask under the hood to intelligently batch requests made during the same event loop tick.

Why dldr?

When building applications that fetch data, you often encounter the N+1 problem - making separate requests for related data that could be batched together. dldr solves this by:
  • Automatic Batching - Groups requests made in the same tick
  • Deduplication - Ensures each unique key is only fetched once
  • Optional Caching - Cache results across ticks for even better performance
  • Tiny Footprint - Minimal overhead with maximum impact
  • Framework Agnostic - Works with any JavaScript/TypeScript project

Quick Example

import { load } from 'dldr';

// Define your loader function
const getPosts = (keys) => sql`SELECT id, name FROM posts WHERE id IN (${keys})`;

// Make multiple requests
const posts = await Promise.all([
  load(getPosts, '123'),
  load(getPosts, '123'), // Deduplicated!
  load(getPosts, '456'),
]);

// Your loader is called just once with ['123', '456']

Get Started

Installation

Install dldr via npm or JSR in seconds

Quick Start

Get up and running with a working example

Caching

Learn how to cache results across ticks

API Reference

Explore the complete API documentation

Key Features

Batching

Automatically batches requests within the same microtask tick

Deduplication

Prevents duplicate requests for the same key

Caching

Optional caching module for persistent results

Type Safe

Full TypeScript support with complete type inference

Zero Config

Works out of the box with sensible defaults

Flexible

Supports custom identity functions and cache implementations

Use Cases

dldr is perfect for GraphQL resolvers, REST API batching, database query optimization, and any scenario where you need to consolidate multiple requests.

GraphQL Resolvers

Avoid the N+1 query problem in your GraphQL resolvers by batching field resolutions.

Database Queries

Reduce database round-trips by batching multiple queries into a single operation.

API Requests

Minimize HTTP requests by grouping multiple API calls together.

Data Loading

Optimize data fetching in React, Vue, or any other framework.

Build docs developers (and LLMs) love