• This repository has been archived on 03/Mar/2023
  • Stars
    star
    144
  • Rank 255,590 (Top 6 %)
  • Language
    JavaScript
  • Created about 13 years ago
  • Updated almost 13 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a client-side web framework in 1,024 bytes

kibi

Goal

An easy-to-use single-page app framework in 1,024 bytes of JavaScript. kibi currently weighs in about 200 bytes less, so there's still room for improvement. You can see it an action on heroku.

Features

Right now, kibi includes:

  • a template engine,
  • a router,
  • a JSONP implementation
  • a page load indicator, and
  • pushState support.

Background

kibi was inspired by running 140byt.es. Having learned so much about tuning tiny code, I figured I would take code golfing to its logical extreme, and create the tiniest web framework possible.

I initially planned to release kibi at JSConf.eu '11, but unfortunately, ran out of time and had to scale back my slides. But I did write some interesting code, and wanted to share it.

This repo is a snapshot of what I had built, published as an exploration of the cool things still possible with very little code. If you'd like to develop it yourself, please feel free to take over this fork!

Approach

Originally, I thought I could take all the byte-pinching knowlege I'd learned with 140byt.es to make the tiniest possible library. I event tried to abstract some of these hacks into helpful libraries to do the golfing for you.

But you know what? It turns out that all those little operator hacks pale in comparison to a higher-level approach to compression. Above several hundred bytes, it pays more to write very consistent code over very hand-optimized code, and then run it through uglify, and then jscrush. Using these two libraries can cut code size in half, assuming you code as regularly as possible to maximize compression, such as by using local variables instead of properties, and reusing property names wherever possible.

Building a kibi app

kibi apps are declarative, and consist of several named/routed templates, each of which lives in its own script tag. When kibi loads, it parses every script tag with a data-kibi attribute into its own template. The data-kibi attribute should be set to a loose JSON object with the following keys:

  • pathname (optional): a regular expression. when this is matched, the template is rendered to the page body.
  • id (optional): a string. this allows templates to be called from within other templates by name, on the global kibi.template object.
  • location (optional): a JSONP url. when a template with a location is rendered, it is rendered using the data returned from the url. pretty neat, eh?

A kibi app should have this structure:

<html>
<!-- use scripts as you would normally-->
<script src="/jquery.js"></script>

<!-- use the text/plain type to avoid evaluation -->
<script type="text/plain" data-kibi='{
  pathname: /^\/$/,
  location: "http://mydomain.com/examplejsonp?callback="
}'>
  <p>Welcome to my site!</p>

  <p>Here is some dynamic content:</p>

  <p><% JSON.stringify(this) %></p>

  <% kibi.template.footer() %>
</script>

<script type='text/plain' data-kibi='{id: "footer"}'>
  <p>This is the footer.</p>
</script>

<script type='text/plain' data-kibi='{pathname: /.*/}'>
  <h1>Not found.</h1>
</script>

<!-- load kibi last to make sure it can find everything -->
<script><!-- inlined kibi source code--></script>
</html>

For a better example, see the kibi sample app itself.

Installation and Setup

To install, enter:

$ npm install kibi

To see the demo, enter:

$ npm start kibi

and then head to http://localhost:8080.

To build kibi and the demo, enter:

$ node ./tools/build.js

from the root of the project.

Building will take a few seconds, and show you the size of the library after compression like this:

building kibi.js...
- raw: 2089 bytes
- uglified: 1124 bytes
- crushed: 1013 bytes
- uglycrushed: 840 bytes
kibi.js built successfully: 840 bytes (-184)

License

Copyright (c) 2011 Jed Schmidt, http://jed.is/

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

140bytes

Once a tweet-sized, fork-to-play, community-curated collection of JavaScript.
HTML
1,031
star
2

lave

eval in reverse: stringifying all the stuff that JSON.stringify won't
JavaScript
896
star
3

fab

a modular async web framework for node.js
JavaScript
732
star
4

browserver-client

à·´ A node.js HTTP server in your browser à·´
JavaScript
638
star
5

authom

A zero-dependency mutli-service authentication tool for node.js
JavaScript
401
star
6

browserver-node

à·´ Browserver proxy for node.js à·´
JavaScript
333
star
7

domo

Markup, style, and code in one language.
JavaScript
308
star
8

certbot-route53

Helping create Let's Encrypt certificates for AWS Route53
Shell
175
star
9

dynamo

DynamoDB client for node.js
JavaScript
141
star
10

building-brooklynjs

My story of how we built BrooklynJS.
136
star
11

rndr.me

an HTTP server that uses PhantomJS to render HTML
JavaScript
133
star
12

weenote

A quick/dirty/tiny tool for creating simple Takahashi-style presentations.
HTML
119
star
13

hyperspider

A declarative HATEOAS API crawler for node.js
JavaScript
114
star
14

sheet-down

A Google Spreadsheet implementation of leveldown
JavaScript
108
star
15

cookie-node

signed cookie functionality for node.js
JavaScript
82
star
16

config-leaf

Hide your sensitive node.js bits in plain sight.
JavaScript
53
star
17

sajak

Simple Authenticated JSON API Kit
JavaScript
33
star
18

dynamo-down

A leveldown API implementation on AWS DynamoDB
JavaScript
31
star
19

localhose

Hose your hosts file for easier local web development
JavaScript
29
star
20

browserver.org

The code for the browserver.org web site.
CoffeeScript
29
star
21

emit

A reactive toolkit for JavaScript
JavaScript
29
star
22

dynamo-client

A low-level client for accessing DynamoDB from node.js
JavaScript
28
star
23

osx-browser-vm

Evaluate JavaScript in local OS X browsers
JavaScript
28
star
24

dynamo-streams

A stream-flavored wrapper for the AWS DynamoDB JavaScript API
JavaScript
25
star
25

wc-jsx-runtime

A JSX transform for Web Components
JavaScript
23
star
26

tmpl-node

a template module for node.js
JavaScript
20
star
27

esbuild-plugin-http-fetch

An esbuild plugin that resolves http(s) modules
JavaScript
19
star
28

skeyma

A JavaScript parser & serializer for {key, value} objects & streams
JavaScript
18
star
29

browserver-router

A platform-agnostic router for HTTP listeners that follow the node.js spec
JavaScript
18
star
30

cfn-api-gateway-custom-domain

API Gateway custom domains as CloudFormation resources, backed by Let's Encrypt
JavaScript
18
star
31

alReady.js

a terse, embeddable, and cross-browser domReady implementation
JavaScript
17
star
32

electric-objects

A node.js API for the Electric Objects EO1 frame
JavaScript
17
star
33

monot

Unique JavaScript dates
JavaScript
15
star
34

google-worksheet-stream

A streaming interface for Google Spreadsheets
JavaScript
14
star
35

dinkumise

Keep ya JavaScripts Dinki-di!
11
star
36

pbsb

getters/setters and pub/sub in one tiny javascript function
JavaScript
11
star
37

twil-eo

Using Twilio, AWS, and Electric Objects to create an MMS-powered family photo frame.
JavaScript
10
star
38

textpanda

web-based text shortcuts for the lazy
JavaScript
8
star
39

diff-stream2

Merges multiple sorted streams into a diffed tuple stream
JavaScript
7
star
40

namedrop

minification for DOM-heavy code
JavaScript
7
star
41

eartag

Tag browsers like farmers tag livestock
JavaScript
7
star
42

autorequire

small module for autorequiring. warning: MAGIC!
JavaScript
6
star
43

sort-stream2

Array.prototype.sort for streams
JavaScript
6
star
44

dynamo-sync

Differential data synchronization for Amazon's DynamoDB
6
star
45

google-oauth-jwt-stream

A readable stream of OAuth access tokens for use with Google APIs
JavaScript
6
star
46

dom-jsx-runtime

A tiny library that turns JSX into DOM operations
JavaScript
6
star
47

node-lacrosse

A node.js streaming API for Lacrosse Alert sensors
JavaScript
6
star
48

abstract-stream-leveldown

A stream-based abstract prototype matching the LevelDOWN API
JavaScript
5
star
49

gist-in-time

a stylesheet for displaying github gist metadata on hover
5
star
50

typd.in

a web-based input method editor for japanese
JavaScript
4
star
51

esbuild-plugin-eval

An esbuild plugin that evaluates a module before importing it
JavaScript
4
star
52

one-character-identifiers

every javascript identifier that fits in a character
JavaScript
4
star
53

jed.is

personal web site
3
star
54

domogenize

Turn static HTML and CSS into declarative JavaScript
JavaScript
3
star
55

ramendan

CoffeeScript
3
star
56

census-topologies

Topologies from the U.S. Census Bureau
Shell
3
star
57

20x20

a simple pecha kucha timer optimized for my iPhone
JavaScript
3
star
58

utfn

a test of the utf-n encoding
3
star
59

esbuild-plugin-bundle

An esbuild plugin that bundles modules before importing them
JavaScript
2
star
60

deno_bundle

A temporary workaround to support bundling with sourcemaps in Deno
JavaScript
2
star
61

ordered-kv-tuple-stream

Aligns multiple ordered k/v readable streams into one
JavaScript
2
star
62

tuple-stream2

Aligns multiple readable object streams into one stream
JavaScript
2
star
63

esbuild-plugin-deno-http

An esbuild plugin that uses Deno to resolve and cache HTTP modules
JavaScript
2
star
64

esbuild-plugin-env

An esbuild plugin that exports the current environment as a module
JavaScript
2
star
65

deno-file-system-access-api

File System Access API for Deno
JavaScript
1
star
66

level-sync

One-way sync for levelup data stores
JavaScript
1
star
67

abevigoda

Abe Vigoda as a Service
JavaScript
1
star
68

esbuild-plugin-view-source

An esbuild plugin that enables built modules to be imported as source
JavaScript
1
star