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

statici

v0.1.5

Published

A way to elimnate network requests before their needed

Downloads

3

Readme

Statici

A way to eliminate network requests before their needed

Installation

npm i statici

Usage

Why should you even use this

The purpose of this library is to provide a way to render client side javascripts requests on the server to reduce load time. Giving the benefit of static delivery with dynamic data. This package is primarily for vanila html projects with a mild to low update frequency and has not been tested on rapid updating projects.

Give all scripts that are to be run and removed the attribute 'statici="true"'

<script statici="true">console.log("I wont be here")</script>
<script>
    dom.addEventListener('customEvent', (evt)=>{
        console.log("I am from the server "+evt.data)
    })
</script>

Example

index.js


const Statici = require("statici")
var build = new Statici('./src-file-directory.html', "build")
await build.buildToFile("./output-path/out.html",{data:"hello from the server"})

src-file-directory.html

<html>
    <body>
    <script statici="true">
        const event = new Event('build'); 
                window.addEventListener("statici", (evt)=>{
            document.getElementById("console").innerHTML =JSON.stringify(evt.data)
        })
        var xmlHttp = new XMLHttpRequest();
        xmlHttp.onreadystatechange = function() { 
            if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
                var doc = document.getElementById("demo");
                var jsonDoc = JSON.parse(xmlHttp.responseText);
                doc.innerHTML=jsonDoc['currentDateTime'];
                document.dispatchEvent(event);
            }
           
        }
        xmlHttp.open("GET", 'http://worldclockapi.com/api/json/est/now', true);
        xmlHttp.send(null);
        </script>
        <p id="demo"></p>
        <p id="console"></p>
    </body>
    </html>

./output-path/out.html

<html>
    <body>

        <p id="demo">2020-07-27T04:02-04:00</p>
        <p id="console">hello from the server</p>
    </body>
    </html>

API

Statici(src, eventName)

parameters

  • src
    • type: string
    • source file directory path
  • eventName optional
    • type: string
    • The name of the event when the page is loaded
    • if empty will use load

return

  • type: Statici class

example

  const build =  new Statici("sample.html",'build')

.setSrc(src)

parameters

  • src
    • type: string
    • source file directory path

example

build.setSrc("newSrc.html")

.setEvent(event)

parameters

  • event
    • type: string
    • The name of the event when the page is loaded

example

build.setEvent('build')

.buildToFile(element, options)

parameters

  • element
    • type: string
    • output file directory path
  • options optional
    • type: json
    • required
      • data
        • type: any
        • the place to store custom data for the front end

return

  • Type: string
  • output file path

example

    build.buildToFile("output.html",{data:"this will be passed to the front end"})

.buildToString(options)

parameters

  • options optional
    • type: json
    • required
      • data
        • type: any
        • the place to store custom data for the front end

return

  • type: string
  • The rendered html file as a string

example

    build.buildToString("output.html",{data:"this will be passed to the front end"})