This is a framework for HTML5 network apps; games and tools in particular.

Ynet internally handles dynamic loading of code modules (aka. JavaScript streaming), which also allows live code updates (aka. runtime code injection), speculative module fetching and seamless resuming after re-connection (without reloading any code, aka. lazy execution). Some syntactic sugar is also included (see below).



  • built-in debug console, supporting colored output
  • compact HTML tree notation
  • meaningful typeOf( var ) where null is "null" and "Ynet" is "string"
  • query and manipulate elements, classes, attributes, etc.
  • easy interface events (supporting click/tap/hold/drag & drop)
  • built-in authentication (Passkey / FIDO2, device / cookie, password, e-mail, QR code)
  • session handler
  • resource loader / progress display
  • handy geometry functions, curves/slopes/splines, vectors and matrix classes
  • n-dimensional typed arrays, unlimited 2D/3D maps, bsp/quad/oct trees, heaps
  • keyboard, mouse, touch and gamepad support
  • database access, including query helpers
  • heartbeat providing a stable "main loop" framerate, also fps measuring
  • tile maps, including A* path finding, terrain generation and more
  • voxel trees for endless worlds, supporting voxel tile maps for quick generation
  • 2D/Canvas rendering and drawing utilities, including image effects
  • 3D/WebGL rendering with shaders, covering pixels / sprites / polygons / voxels
  • sound and music playback, supporting multiple effects (pitch, reverb, distort, etc.)
  • sound sprites (multiple sounds in one file)
  • QR data transfer (ie. reader and generator)


Here are some random screenshots from various projects:

JS syntactic sugar

The delay( ms ) structure is a shortcut for setTimeout() calls:

delay( 1000 ) { doSomethingAfterOneSecond(); }

The benchmark( num ) structure is a shortcut to bench(); for( num ) { ... } mark();

benchmark( 1000 ) { doSomethingThousandTimes(); }

After 1000 iterations, the execution duration in ms will be printed to the Ynet console.

Ynet supports multi-line strings in code:

var list = "/* This is a multi-line string. */";

Easily check arguments for their data type and range:

function printText( id, name, message, opacity ) { /// id = uint /// name = char (16) [a-z] /// message = text (2k) /// opacity = float (0-100) }

In this example id can be any positive integer, name must be a string of exactly 16 lowercase letters, message is a UTF8 string up to 2000 characters length and opacity can be any number from 0 to 100. Failing a test throws an error, providing name, data type, value and expected range of the argument.

Quickly print out debug information:

function start() { //> Now starting }

The text Now starting will be printed to the console.

Simplest counting loops:

for( var a to 5 ) { print( a ); }

Prints: 0 1 2 3 4

Simple counting loops:

for( var a = 2 to 5 ) { print( a ); }

Prints: 2 3 4

Stepped counting loops:

for( var a = 0 to 5 step 2 ) { print( a ); }

Prints: 0 2 4

Iterating through array values:

var list = [ "The", "answer", "is", "42" ]; for( list as value ) { print( value ); }

Prints: The answer is 42

Iterating through array indices and values / also works on Map and map-like objects:

var list = [ "Ynet", ".", "dev" ]; for( list as index => value ) { print( index + " = " + value ); }

Prints: 0 = Ynet 1 = . 2 = dev

Alias syntax for often-used functions:

$client.getTile( x,y ) { // The actual function } $client.get => getTile; // Function alias

The getTile function can now be called through item.get( 0,0 );

HTML elements

Easily create HTML interfaces:

html( "/* <main.homescreen> <h1> Welcome <p#intro> This is a sample application. <p> Here's a list of cars: <ul.items> <li.grey> DeLorean DMC-12 <li.black> Batmobile <li.blue> Mach 5 <p.form> <input/text #txtName hint="Enter name" assign="onNameChange"> <input/int #txtNumber.right hint="Enter number" value="2"> <select id="lstCountry" hint="Select country"> <option content="Lothlorien"> <option content="Oceania"> <option content="Gilead"> <button assign="onButtonClick" content="Continue"> */" ).append();

There are multiple ways to define the id, class and content (eg. p#intro and p id="intro" is equivalent). Some special attributes (such as assign) will be recognized and assigned to the corresponding Ynet UI events. The final append() call adds this structure to the body.

Other namespaces (ie. svg and ynet) can be accessed through the colon sign.

The following code creates a SVG line element:

html( "<svg:line>" );

The ynet namespace simplifies the creation of everyday complex HTML elements.

html( "<ynet:knob>" ).text( "Enable dark theme" );

This creates your typical "on/off" switch button with a sliding bullet.

Similar to the knob switch, radio buttons can be assembled as follows:

html( "<options>" ) .assign( "selectAction" ) .addOption( "fruit", "Eat fruit" ) .addOption( "water", "Drink water" ) .addOption( "table", "Dance on table" );

Interacting with the radio buttons will trigger the selectAction event to handle this.value().

CSS syntactic sugar

body { color:#000; } // Inline comment

CSS only allows /* block comments */ but Ynet fixes this stupid decision.

div { scroll:y; }

Allow scrolling in x, y or xy direction. Translates to a overflow and touch-action setup.

border-left-right:1px solid;

border-top-bottom:1px solid;

Border setup for two opposite sides.

if( w < 200 )

Included if the screen width is less than 200 px.

if( h >= 10em )

Included if the screen height is at least 10 em.

if( ws )

Included if the screen is in landscape mode (width > height).

if( hs )

Included if the screen is in portrait mode (height > width).

if( cursor )

Included if the primary input is the mouse cursor.

if( touch )

Included if the primary input is the touch screen.

button:hover { background:#FFF; }

Ynet automatically applies :hover styles only for mouse cursors.

button:ui { background:#FFF; }

The custom :ui selector applies to both, :focus and :hover. This allows easily setting up the same styles for mouse and keyboard interaction.

$red = #F00; body { color:$red; }

CSS variables made simple.

Conditional CSS

To avoid the limited CSS media queries and their weird syntax, Ynet offers custom CSS conditions:

$css( aspect < 1.0 || core.domain.indexOf( "mobile." ) == 0 ) { nav, main, footer { display:block; width:100%; } h1 { text-align:center; } }

This style will be included in portrait mode (w / h < 1.0) or if the app domain starts with mobile.. Since this is simply evaluated JavaScript code, literally anything can be used, eg. custom variables or function calls. Common variables like w, h, aspect are pre-defined and can be used as shown.

Ynet modules

core Ynet core (server/client). 115 KB
html HTML (creation, manipulation, dragging, language translation). 44 KB
image Image (creation, manipulation, drawing, color effects) and color class (RGB/CMYK/HSL/Greyscale, alpha channel). 22 KB
audio Sound effects and music playback (sound sprites, volume/pitch variations, reverb/distortion effects, seamless looping, crossfading, equalizer). 10 KB
login Account manager (FIDO2, password, e-mail, device) and session handler. 30 KB
map 2D map class for editing (cut/copy/paste areas, insert/delete cols and rows, rotate/scale/flip/blur map, terrain generator) and tile-based games (wrap/endless mode, A* path finding). 17 KB
math Numerous math and geometry functions, randomization, vector / matrix classes. 25 KB
webgl WebGL 1+2 (shaders, textures, polygons, lights, shadows). 72 KB
voxel Voxel addon (loader, renderer, shaders). 44 KB
data Buffers (array_map, growbuffer, heap, ringbuffer) and interpolation (curve, slope, tween) 21 KB
+ Everything else (database, gamepad / keyboard, hashing, heartbeat / fps, resource loader) 34 KB

Complete chat example

The following code is a complete example running a simple console-based chat. Users can enter a name, get a list of all connected users, get notified when someone joins or leaves, and can broadcast plain text messages. For simplicity, a user counts as logged in if the username property is set (otherwise the user is connected but didnt' choose a name yet).

Note that the print event is built-in and text coloring is done through color tags (eg. <lr> means light red). The application is started by running node main.js on the server.


// Ynet starter require( "../core.js" ).start({ port:8000 });


// Create the Ynet $s / $c / $b scopes core.createScopes( exports ); // $s means server code $s.module.init() { // Start listener core.listen( core.port ); } $s.core.onConnection( con ) { // Someone connected to the server // Add the username property con.username = null; // Now send the chat module (this file) and wait for input con.transmit( "chat" ); } $s.core.onDisconnect( con ) { // The connection to this user was lost var name = con.username; if( !name ) { return; // User was not logged in } // Logout by clearing the username con.username = null; // Broadcast who left (note that the "print" event is built-in) for( core.connections as c ) { if( c.username ) c.send( "print", "<lr>Left: " + name ); } } // $c means client code $c.module.create( initial ) { // The client module is ready if( initial ) { // Display a welcome message print( "<w>Welcome to the chat!" ); print( "<w>Enter your username first:" ); } } // And here's the beef, client sending and server receiving $c.core.onConsoleInput( data ) { // The user pressed enter // Forward the input to the server... if( data.length > 0 ) core.send( "chatInput", data ); } $s.events.chatInput( data ) { // ...and here the server receives the input // Trim spaces and sanitize HTML first data = data.trim().hss(); if( data.length < 1 ) { return; // Empty message } // Check login state if( this.username ) { // Name present, forward the message game.doForward( this, data ); } else { // No name set, try to login first game.doLogin( this, data ); } } $s.game.doLogin( con, data ) { // Only allow basic letters and numbers var name = data.replace( /[^a-zA-Z0-9]/g, "" ); if( name.length < 1 ) { // No valid chars left return con.send( "print", "<lg>Only invalid characters!" ); } if( name != data ) { // Send what is left return con.send( "print", "<lg>Try this instead: " + name ); } // Set username con.username = name; // Broadcast who joined for( core.connections as c ) { if( c.username ) c.send( "print", "<lg>Joined: " + name ); } // Collect a list of all usernames... var list = []; for( core.connections as c ) { if( c.username ) list.push( c.username ); } // ...and send it to the new user con.send( "print", "<lb>Users: " + list.join( ", " ) ); } $s.game.doForward( con, text ) { // Add yellow name var msg = "<y>" +con.username+ ": <e>" +text; // Broadcast message to everyone else for( core.connections as c ) { if( c != con && c.username ) c.send( "print", msg ); } }


Not (yet) available to the public, sorry. This is a private project.


Ynet is the HTML5-based successor of the YDK framework, which was created around 2005 as a Visual Basic 6.0 convenience API. Large parts of the original YDK were DirectX wrappers, so one could easily render graphics (shapes, 2D images and later even 3D models), play sounds (variing pitch and volume), setup music (fading and looping automatically), handle input devices (including rumble effects) and many things more (networking, path finding, data encryption, scripting, etc.).

Unfortunately Microsoft decided to discontinue the DirectX extension for VB6 (the last version was DirectX 8.1) and even VB6 itself, in order to push their dotNet framework. After some roaming through the realms of early HTML5 (before WebGL was available), Java and even Flash, the final decision was to use HTML5 and a node.js server respectively. Finally, in the summer of 2020, the Ynet.dev project was born and here we are.

The lesson of this journey is to stick with standards, not companies.

Although I am very disappointed to see WebGL being discontinued in favour of the upcoming WebGPU API. I was strongly hoping to see geometry shaders in WebGL one day...