Giter VIP home page Giter VIP logo

cljb's Introduction

cljb

Browser support for ClojureScript.

What is cljb?

cljb is a tiny JavaScript shim that allows you to run ClojureScript directly in the browser without the need for local build tools.

Why is it called cljb?

cljb is short for "clojure in the browser".

Why is cljb relevant?

I'm not sure it is, but I think it's pretty neat :)

I've always found it strange that compile-to-js languages are your only option for building web apps. A web browser is more than a compilation target - it's is own environment with great support for runtime debugging and interactivity. There's great potential for interactive development but many of us choose to use other languages, libraries and frameworks that shift the development experience from happening within the browser to a hybrid of browser + external tools. I don't think it has to be this way and cljb is a PoC of what an alternative to a JS-only browser could look like.

How do I use it?

You first have to make the cljb runtime available in your web app:

<head>
  ...
  <script src="https://<the-path-to-the-hosted-shim>.js"></script>
  ...
</head>

You then have the option to either include .cljb files just as you would any other .js file in your web app:

<script src="/path/to/my/web_app.cljb"></script>

Or you can inline cljb code just as you would with JS code:

<script type="application/cljb">
  (defn say-hello [name]
    (println "Hello" name))

  (say-hello "Frodo")
</script>

How does it work?

cljb includes the ClojureScript runtime, prebundled using the fantastic Clojure compiler sci, alongside a default set of libraries that I think many web app developers will find useful.

When cljb is included in your web app it will wait for the page to load, find all external and inlined cljb code and execute it within the cljb runtime in the order that it appears on the page.

Bundled libraries

These come pre-bundled with cljb, lmk if you'd like to see another library on this list.

  • re-frame
  • reagent

Development

cljb's source code is located under src/ and example code under public/.

Start by running:

bun start

This will auto compile cljb's source code whenever it's edited and start a web server on localhost:3000 that serves the public/ folder.

Navigate to http://localhost:3000 and start playing around.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.