npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tiny-browser-framework

v1.1.1

Published

Minimal Client JS Framework

Downloads

12

Readme

Tiny Browser Framework

npm Build Status

Tiny browser web framework, which communicates to the server via a websocket. All DOM changes are performed using HTML provided by the server.

Minified size is 2.23 Kb which when transmitted compressed is less than 1Kb!

Usage

Add the following script tag at the bottom of your HTML as follows:

<script src="https://unpkg.com/tiny-browser-framework/dist/index.min.js"></script>

Then add data-url attributes to any buttons on your pages, the value of this would be the data that will be sent over the websocket to the server to process.

<button data-url="/something?a=b">An example button</button>

No change is required for any forms present on your pages.

Full example HTML available at example/example.html.

Specification

The server does all the heavy lifting and the browser is just used for updating fragments of HTML on the page, which keeps the clientside logic minimal.

Any state, authentication or persistence is not a concern of this client framework, these can also be managed by the server, but might involve a client side element such as setting cookies or using other JS libs for OAuth etc.

Data is sent to the server when an augmented element on the page is triggered, the server may then response with zero or more fragments of HTML to update the page.

The server may also return HTML fragments to the client based on server events rather than user actions, possible scenarios for this could be:

  • Message received from pub/sub topic.
  • Time based logic.
  • Server state change, such as a multi-user system.
  • Long running job finishes, such as encoding an uploaded video.

This means that the browser does not need to wait for the server to return a final response. It could return a number of fragments in a timely manner to provide a helpful UI until a long operation finishes.

Client

Forms are augmented automatically using their action URLs.

Other clickable elements will be augmented if the data-url property is set. The value is the server URL where a GET request to handle the action resides.

Server

A server must return JSON from websocket requests to /websocket in the following format:

[{
	"action": "append|replace",
	"container": "ID of container element to update",
	"content": "HTML string"
}]

As this is an array the server may return 0 or more elements that need to updated at once.

An example of this is:

[{
	"action": "append",
	"container": "todos",
	"content": "<li>Another todo</li>"
}, {
	"action": "replace",
	"container": "numTodos",
	"content": "You have <b>5</b> todos."
}]

The above example would add another child to the element with the ID of "todos" and replace the contents of the element with the ID of "numTodos".

Live demo

https://tiny-browser-framework.herokuapp.com/

This is a simple todo list app, which also supports a reminder for an item.

This example shows the following:

  • Using a cookie session with a websocket.
  • Direct DOM change from user action.
  • Indirect DOM change from user action.
  • DOM change via timed event.

Developing

Install the package:

npm install tiny-browser-framework

Then create a script tag in your HTML to reference the src/index.js file.

See the example directory for more information.

Included node.js express server example

To run the example server use:

nvm use
npm install
npm start

Then open http://localhost:3000/ in your browser.

Compatibility

Browser shims for modern browser functionality are not included in this project.

The following would be required:

Todo

  • Implement more actionable elements, such as images or links etc.
  • Implement more ways to trigger an element such as onblur, onfocus, onscroll etc.