whatisgithub

What is greenlet?

developit/greenlet — explained in plain English

Analysis updated 2026-06-26

4,694JavaScriptAudience · developerComplexity · 2/5LicenseSetup · easy

In one sentence

A tiny JavaScript library that moves any async function into a background browser thread with one line of code, keeping your page fast and responsive during slow or heavy tasks.

Mindmap

mindmap
  root((greenlet))
    What it does
      Moves functions to background
      Prevents page freezing
      One-line setup
    How it works
      Wraps async functions
      Uses Web Workers
      Self-contained context
    Use Cases
      Heavy computations
      Data fetching
      JSON parsing
    Constraints
      No external references
      Small data payloads
      CSP policy update needed
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Move a slow data-fetching and processing function off the main thread so the UI stays responsive.

USE CASE 2

Run CPU-heavy computations in the background without blocking user interactions on the page.

USE CASE 3

Wrap an existing async function to run in a Web Worker without writing any Worker boilerplate.

What is it built with?

JavaScriptWeb Workers

How does it compare?

developit/greenletsupasate/connected-react-routerapple/password-manager-resources
Stars4,6944,6954,696
LanguageJavaScriptJavaScriptJavaScript
Setup difficultyeasymoderateeasy
Complexity2/53/51/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

Functions passed to greenlet must be fully self-contained, they cannot reference variables or imports from the surrounding file.

Use freely for any purpose including commercial projects, as long as you keep the copyright notice.

So what is it?

Greenlet is a tiny JavaScript library that takes an async function and moves it into a separate background thread in the browser. Normally, JavaScript in a web page runs on a single thread, which means that heavy or slow computations can make the page feel sluggish or unresponsive while they run. Browsers offer a feature called Web Workers that lets you run code in a separate thread, but setting one up directly involves some boilerplate. Greenlet removes that setup overhead. You pass your function to greenlet once, and it returns a new version of that function that runs in its own worker thread whenever you call it. The function must be self-contained, meaning it cannot reference variables or imports from the surrounding file, because it runs in a completely separate context. The README notes that greenlet works best when the data being passed in and out is small, since larger data has to be copied between threads. The README shows an example where a function fetches data from a network API and extracts just one field from the response. The whole function is wrapped with greenlet so the fetch and JSON parsing happen in the background without blocking anything else on the page. The library is very small, around one kilobyte compressed. It supports all major browsers including Internet Explorer 10 and later. If your site uses a Content Security Policy for security, you need to add specific worker permissions to your policy for greenlet to work. The library is MIT licensed and was created by Jason Miller, who also made a related library called workerize for moving entire modules into workers.

Copy-paste prompts

Prompt 1
Using greenlet, wrap this data-fetching function so it runs in a background thread and my UI stays responsive: [paste your function here].
Prompt 2
Show me how to move a slow JSON parsing step into a Web Worker using greenlet with one line of code.
Prompt 3
I have an async function that does heavy number crunching. How do I use greenlet to run it off the main thread?
Prompt 4
Demonstrate a before-and-after comparison: a blocking function on the main thread vs the same function wrapped with greenlet.

Frequently asked questions

What is greenlet?

A tiny JavaScript library that moves any async function into a background browser thread with one line of code, keeping your page fast and responsive during slow or heavy tasks.

What language is greenlet written in?

Mainly JavaScript. The stack also includes JavaScript, Web Workers.

What license does greenlet use?

Use freely for any purpose including commercial projects, as long as you keep the copyright notice.

How hard is greenlet to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is greenlet for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.