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

ube-ssr

v0.1.4

Published

An SSR, islands friendly, way to render ube components

Downloads

4

Readme

µbe-ssr

lego board with µbe logo

Original Social Media Photo by JOSE LARRAZOLO on Unsplash

An SSR, islands friendly, way to render µbe components on the page, either dynamically, or statically, producing single SPA like files that are also easy to share.

Features

  • based on js-in-json
  • incremental or "all at once" hydration via builtin elements (no Custom Elements, no Polyfills needed)
  • can generate, or build, on the fly, or produce static HTML pages with all dependencies on demand served within it (no network requests)
  • bootstraps and serve pre-cached js-in-json content in 0 to few milliseconds

How to

import http from 'http';
import ube from 'ube-ssr';

const {
  // provides same ube helpers
  render, html, svg,
  // plus utilities to define components
  // and bootstrap before serving
  include, bootstrap
} = ube({
  // all same options available in js-in-json
  ...options,

  // plus optional `flush`:
  //  if `incremental`, will flush after each component,
  //  otherwise will add a <script> with all needed content
  //  after rendering
  flush: 'incremental',

  // plus optional `module`:
  // if `true`, all scripts are served as inline
  // non-blocking type="module"
  module: true
});

// define what µbe should be included, and what
// kind of tagName it represents on the page
const Div = include('comp/div.js').as('div');
const Button = include('comp/clicker.js').as('button');
// if not used in the template, their content won't be
// on the page neither


// prepare the islands/sessions to use automatically
await bootstrap(
  // if a cache object is passed, it'll be used.
  // if a boolean `true` is passed, and the cached
  // js-in-json file exists (output), it will use it.
  // in all other cases, it builds the cache and,
  // if the output was specified, will save it there
  !!process.env.PRODUCTION
);

// http example
http
  .createServer((req, res) => {
    res.writeHead(200, {'content-type': 'text/html;charset=utf-8'});
    render(res, html`
      <!doctype html>
      <${Div}>Hello SSR 👋 </${Div}>
      <!-- incremental flushes example -->
      <${Div}>Hello Again 👋 </${Div}>
    `);
  })
  .listen(8080);

See the test example or the produce HTML output.

Find the list of js-in-json options and remember that the root folder is the only mandatory field, and it should point at where your client-side JS files / components are.

In Details

µbe components are like custom elements, builtin or not, with a unique feature: they don't need a registry, and there's never a name clashing.

These components are the best one to hydrate, because they don't require changes in the layout, like it is for custom elements.

With µbe-ssr this potential goes beyond client-side components definition:

  • layout can be served same way µhtml-ssr does already
  • components can be simple (only behaviors attached on the fly) or could render themselves on the fly
  • the hydration can be instantaneous (using flush: "incremental" special option) or performed only at the end of the rendered content
  • the JS code is automatically split in chunks and dependencies so that only rendered components lands once, as definition, and these are incrementally hydrated on the fly, or at the end

Both babel and minify options from js-in-json makes it super easy to debug real/native code, and can be set as false only during development, with minify and output able to produce best results in terms of performance and portability.

Any static site host can work without issues, but once the js-in-json cache is produced, creating highly dynamic, or reactive, pages, is also possible and pretty damn fast.