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

eco-webserver

v1.0.15

Published

Static file NodeJs server

Downloads

15

Readme

license docker pulls npm version ci status

eco-webserver

The objective of eco-webserver is to propose a nodejs server able to reduce the network footprint of a static site or a single page application (SPA).

To do so, the server uses different strategies depending on the types of files it hosts.

Features

  • [X] Cache files
  • [X] Reverse proxy
  • [X] Isomorphic application
  • [X] GZIP implementation
  • [X] Include Etag
  • [X] Include html minifiers
  • [X] Include css minifiers
  • [X] Include json minifiers
  • [X] Include js minifiers with terser
  • [ ] Optimize images and convert them to webp
  • [ ] Optimize svg path
  • [ ] Optimize fonts and convert them to woff2

Usage

Installation

npm install -g eco-webserver

Command line

cd project
eco-webserver

By default, the eco-webserver command does not take any parameters. If no configuration file is present in the current directory, the application will automatically create one.

Configuration

Create ecoconf.js at the base path of the project :

module.exports = {
    port: 8080,
    cacheCycle: 1800,
    distDir: "dist",
    cacheDir: "cache",
    logDir: "/tmp/eco-webserver.log",
    enableIsomorphic: true,
    header: {
        "Server": "eco-webserver",
        "Cache-Control": "max-age=86400",
        "X-XSS-Protection": "1;mode=block",
        "X-Frame-Options": "DENY",
    },
    contentType: {
        "mp4": "video/mpeg",
    },
    proxy: {
        "/articles": "https://articles.flavien.io/"
    },
}
  • port: The default port of the application.
  • cacheCycle: Duration in seconds between two cache check cycles.
  • distDir: Location of website files to be exhibited.
  • cacheDir: Location of the working cache.
  • logDir: Location of log file.
  • enableIsomorphic: Calculates a rendering of the JavaScript scripts before sending the page to the client.
  • header: Html headers of the different queries.
  • contentType: Allows you to add Content-Types if those supported by default by the application are not enough.
  • proxy: Allows you to associate a remote resource with a local URL in order to cache it.

For PaaS or Docker platform users, it is possible to inject configuration through environment variables :

  • ECO_PORT: The default port of the application.
  • ECO_CACHE_CYCLE: Duration in seconds between two cache check cycles.
  • ECO_DIST_DIR: Location of website files to be exhibited.
  • ECO_CACHE_DIR: Location of the working cache.
  • ECO_LOG_DIR: Location of log file.

With Docker

Ports

  • 8080: HTTP

Volumes

  • /dist
  • /cache

Docker-compose example

dns:
  image: flavienperier/eco-webserver
  container_name: eco-webserver
  restart: always
  volumes:
    - ./dist:/dist
    - ./cache:/cache
  ports:
    - 8080:8080
  environment:
    ECO_CACHE_CYCLE: 1800

File organisation

If a client queries an unknown URL, the server will automatically redirect the request to the index.html file. If the server has a 404.html file, the server will redirect its requests to this file.

How the cache works ?

Each time a user requests a resource, it is cached. If the resource is requested again, its TTL will be incremented by 1 to a maximum of 10.

At each cache cycle (every 15 minutes in the default configuration), all TTL values are decremented by 1 and those falling to 0 are deleted from the cache.

Minification operations on resources are kept in a disk cache. The objective here is not to redo a minification operation that would have already been done in the past. Consequently, the cache associates the sha256 sum of a resource with its result after processing.