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

connection-middleware

v0.1.0

Published

A node HTTP middleware for adding a chunk of JS and a meta tag to determine the connection abilities of the end-user.

Downloads

2

Readme

connection-middleware

Get connection rules based on document download time.

Web performance is an important aspect of caring for the end-user. It is important to have your application progressively enhance based on the connection abilities of your end-user. Connection middleware returns an HTML document with an IIFE that will get a rough guess at the connection speed and assign content rules to the window. In addition, the completion of the function will fire a siteready event.

Install

$ yarn add connection-middleware

Usage

const polka = require('polka');
const connectionMiddleware = require('connection-middleware');

const someHtml = require('./some/html');

polka()
    .use(connectionMiddleware())
    .get('/', (req, res) => {
      res.render(someHtml);
    })
    .listen(8080);

API

connectionMiddleware([options])

Returns a Node middleware function which assigns a render method to the response interface.

options

ads

Type: '3g' | true

Default: false

Ads suck, especially when they are driven by 3rd-parties. By default ads are turned off on all connection types, with the lowest connection type that will allow addes being 3G. When true, only 4G will allow ads to load.

But what about my ad revenue?

adTracking

Type: '3g' | true

Default false

Letting ad companies float random trackers around your site is border-line irresponsible, but if you insist, we'll only let you do that on 3G and 4G. The lowest connection type that will allow ad-tracking is 3G, with 4G being the default when true.

analytics

Type: '2g' | '3g' | '4g' | false

Default: 3g & 4g true; et al false

Analytics can be super useful (though I highly recommend something like Simple Analytics because letting an ad company do all your analytics seems like a really bad idea). So we allow them as low as 2G, but use them wisely. If you're doing anything beyond basic page visit tracking I recommend lumping that in with adTracking.

hdVideo

Type: boolean

Default: true

HD Video's are sweet, but we only allow them at 4G, for obvious reasons. If you think it's better for your users to not pull HD content, or your video content isn't super important, you can disable it.

js

Type: boolean

JavaScript is awesome, but it can readily bloat your site and harm your user all in an effort to make a developer's life a little bit easier. If you want to use the same content code in multiple contexts (like text.npr.org) you may want to disable all JavaScript.

render(html)

An HTML document that includes at least a valid <head> section and a valid <body> section.

Window.serverConnection

When the page loads the IIFE will fire, assigning server connection settings to the window based on the browser connection and the options you provided to the server.

Slow 2G

{
    ads: false,
    audio: false,
    css: false,
    img: false,
    js: false,
    tracking: false,
    video: false,
}

2G

{
    ads: false,
    audio: false,
    css: {
    type: 'enhanced'
    },
    img: {
    resolution: 'sd',
    fileTypes: ['lossy'],
    },
    js: {
    type: 'enhanced',
    },
    tracking: {
    analytics: true,
    ads: false,
    },
    video: false,
}

3G

{
    ads: false,
    css: {
        type: 'enhanced'
    },
    img: {
        resolution: 'hd',
        fileTypes: ['lossy', 'lossless', 'animated'],
    },
    js: {
        type: 'app',
    },
    tracking: {
        analytics: true,
        ads: false,
    },
    video: {
        resolution: 'sd'
    },
}

4G

{
    ads: false,
    css: {
        type: 'app'
    },
    img: {
        resolution: 'hd',
        fileTypes: ['lossy', 'lossless', 'animated'],
    },
    js: {
        type: 'app',
    },
    tracking: {
        analytics: true,
        ads: false,
    },
    video: {
        resolution: 'hd'
    },
}