WinterJS

A blazing-fast JavaScript server that runs Service Workers scripts accordin...

README

winterjs


WinterJS is blazing-fast JavaScript server that runs Service Workers scripts according to the Winter Community Group specification.

WinterJS is able to handle up to 100,000 reqs/s in a single laptop (see Benchmark).


Note: WinterJS is not officially endorsed by WinterCG, despite sharing "Winter" in their name. There are many runtimes supporting WinterCG, WinterJS being one among those.


Running WinterJS with Wasmer


The WinterJS server is published in Wasmer as [wasmer/winterjs](https://wasmer.io/wasmer/winterjs).

You can run the HTTP server locally with:

  1. ```shell
  2. wasmer run wasmer/winterjs --net --mapdir=tests:tests tests/simple.js
  3. ```

Where simple.js is:

  1. ```js
  2. addEventListener('fetch', (req) => {
  3.   req.respondWith(new Response('hello'));
  4. });
  5. ```

Building from source


WinterJS needs to build SpiderMonkey from source as part of its own build process.
Please follow the steps outlined here to make sure you are ready to build SpiderMonkey: https://github.com/wasmerio/mozjs/blob/master/README.md.

You also need to do this before installing WinterJS with cargo install, which builds WinterJS from the source instead of downloading pre-built binaries.

Once you can build SpiderMonkey, you simply need to run cargo build as usual to build WinterJS itself.

Running WinterJS Natively


You can install WinterJS natively with:

  1. ```
  2. cargo install --git https://github.com/wasmerio/winterjs winterjs
  3. ```

Once you have WinterJS installed, you can simply do:

  1. ```shell
  2. winterjs tests/simple.js
  3. ```

And then access the server in https://localhost:8080/

How WinterJS works


WinterJS is powered by SpiderMonkey, Spiderfire and hyper
to bring a new level of awesomeness to your Javascript apps.

WinterJS is using the WASIX standard to compile to WebAssembly. Please note that compiling to WASIX is currently a complex process. We recommend using precompiled versions from [wasmer/winterjs](https://wasmer.io/wasmer/winterjs), but please open an issue if you need to compile to WASIX locally.

Limitations


WinterJS is fully compliant with the WinterCG spec, although the runtime itself is still a work in progress.
For more information, see the API Compatibility section below.

WinterCG API Compatibility


This section will be updated as APIs are added/fixed.
If an API is missing from this section, that means that it is still not implemented.

The following words are used to describe the status of an API:

✅ Stable - The API is implemented and fully compliant with the spec. This does not account for potential undiscovered implementation errors in the native code.
🔶 Partial - The API is implemented but not fully compliant with the spec and/or there are known limitations.
❌ Pending - The API is not implemented yet.

|API|Status|Notes|
|:-:|:-:|:--|
|console|✅ Stable|
|fetch|✅ Stable|
|URL|✅ Stable|
|URLSearchParams|✅ Stable|
|Request|✅ Stable|
|Headers|✅ Stable|
|Response|✅ Stable|
|Blob|✅ Stable|
|File|✅ Stable|
|FormData|✅ Stable|
|TextDecoder|✅ Stable|
|TextDecoderStream|✅ Stable|
|TextEncoder|✅ Stable|
|TextEncoderStream|✅ Stable|
|ReadableStream and supporting types|✅ Stable|
|WritableStream and supporting types|✅ Stable|
|TransformStream and supporting types|🔶 Partial|Back-pressure is not implemented
|atob|✅ Stable|
|btoa|✅ Stable|
|performance.now()|✅ Stable|
|performance.timeOrigin|✅ Stable|
|crypto|✅ Stable|
|crypto.subtle|🔶 Partial|Only HMAC, MD5 and SHA algorithms are supported

Other supported APIs


The following (non-WinterCG) APIs are implemented and accessible in WinterJS:

|API|Status|Notes|
|:-:|:-:|:--|
|[Service Workers Caches API](https://www.w3.org/TR/service-workers/#cache-objects)|✅ Stable|Accessible via `caches`. `caches.default` (similar to [Cloudflare workers](https://developers.cloudflare.com/workers/runtime-apis/cache/#accessing-cache)) is also available.
The current implementation is memory-backed, and cached responses will *not* persist between multiple runs of WinterJS.