Why Webscript?
Tags: webdev, javascript, showdev, html
Published: 2020-05-25 15:27:59

Webscript is an HTML-like Javascript syntax for defining, creating, composing and manipulating DOM elements. It is for creating web applications. It is like HTML but it is Javascript.

1. It has zero dependencies.
2. It is small. It's size is about 2KB.

[See the Webscript Github repository.](https://github.com/mudgen/webscript)

#So Why Webscript?

1. Webscript is much more capable than HTML.
2. Webscript is a nicer syntax than Hyperscript.
3. Webscript is more flexible and capable than HTML templating languages like HTM and lit-html.
4. Webscript works really well with Javasacript because Webscript is Javascript.
5. No need for a compiler or special tooling.

You might not believe it or think it at first but HTML and Javascript don't go together well. They started out together and have been together so long that it might seem normal they are used together. Take a step back and think about the solutions that exist to make them work together.

[JSX](https://reactjs.org/docs/jsx-in-depth.html) is a compiler on top of Javascript that puts HTML in Javascript. The many templating languages such as used by [Vue](https://vuejs.org/v2/guide/syntax.html) and other frameworks try to put Javascript or custom programming languages into HTML.

If Javascript and HTML went together, they would just be used together. But they are not just used together. They are forced together this way and that way. They are oil and water. They don't go together.

If you think about it, it makes sense that they don't go together. They are completely different languages with different purposes. HTML is a markup language with a very specific purpose: create static documents that link to each other. Javascript is a general purpose programming language for creating software. 

It is a common mistake to think that web pages are HTML. They are not. Web pages are the browser DOM, not HTML. It is possible to create web applications without any HTML by building the DOM up with Javascript. The reason this hasn't happened much is because the native way to do this in Javascript, using the function `document.createElement`, is terribly inelegant compared to HTML. It is true that HTML is a nice, succinct language for telling the browser what DOM elements to make. As a markup language, that's what it has to offer.

But Javascript is a dynamic and expressive language. This question should be asked: Is it possible to find within Javascript's features a declarative, succinct, clear syntax for telling the browser what DOM elements to create? The answer is, yes. And that is Webscript.

Of course, with Javascript we can go far beyond just telling the browser what DOM elements to initially create. With Javascript we can change DOM elements over time, we can make new DOM elements when the time is right, we can hide them, we can get rid of them and we can compose them in many ways. If our basic tool for creating DOM elements is Webscript, not HTML, we can just work with it, because it is Javascript.

*Why Webscript? Because Javascript works best with Javascript and Webscript is Javascript.*

[Find out more about Webscript.](https://github.com/mudgen/webscript)

Follow me on twitter: https://twitter.com/mudgen