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

mojito-jscheck

v0.1.6

Published

This utility allows you to find out whether the user agent has JavaScript support as you are serving the request!

Downloads

3

Readme

mojito-jscheck

mojito-jscheck allows a Mojito server to know whether the user agent has JavaScript enabled while handling a request coming from that user agent!

Build Status

Build Status

Usage

In your app's package.json, add the mojito-jscheck package as a dependency.

In your application configuration file, add the mojito-jscheck middleware. Note that it needs to appear after mojito-parser-cookies since it uses req.cookies...

"middleware": [
    ...
    "mojito-parser-cookies",
    ...
    "./node_modules/mojito-jscheck/middleware/mojito-jscheck.js",
    ...
]

In a controller, add mojito-jscheck-addon as a dependency. Then, call ac.jscheck.run() before ac.done(). This puts you into the jscheck cycle of redirects and cookie-setting which will establish your status.

If you're running jscheck in your app, you can check status at any time with ac.jscheck.status(), which returns either "enabled" or "disabled". If jscheck itself is disabled, ac.jscheck.status() returns "indeterminate".

How it works

  • Initially, we don't know whether the user agent supports JavaScript. In that state, ac.jscheck.status() reports "enabled". Why? Because JavaScript is supported by 95 to 99% of the web traffic (depending on the locale...) and applications should optimize for the most overwhelmingly common cases... However, it is important to design web pages to degrade gracefully in case this guess happened to be incorrect (which will happen, albeit very rarely due to the persistence of the cookie we set)
  • When calling ac.jscheck.run() in the "enabled" state, the jscheck add-on inserts a META tag inside a NOSCRIPT tag to redirect the user to [originalUrl]+&js=0
  • The jscheck middleware sees js=0 in the url and sets a cookie (js=0).
  • The jscheck add-on sees the cookie and reports the status as "disabled".
  • When calling ac.jscheck.run() in the "disabled" state, the jscheck add-on inserts a SCRIPT tag which removes the cookie if the user has enabled JavaScript since the cookie was initially set.
  • Status returns to "enabled". If the user ever disables JavaScript, the redirect sets the whole cycle in motion again.

This system relies on two basic assumptions:

  • The overwhelming majority of user agents have JavaScript turned on.
  • JavaScript does not get switched on or off very often...

Configuration

Any part of the configuration is optional. Here is a complete example:

"jscheck": {
    "enabled": true,
    "param": "foo",
    "cookie": {
        "name": "bar",
        "sub": "baz",
        "domain": ".my.domain.com",
        "expiration": 2592000
    }
}

With jscheck.enabled set to false, ac.jscheck.status() will return "indeterminate" and ac.jscheck.run() will not execute any meaningful code.

Notes

  • jscheck does not support setting a sub-cookie. When writing the code, we considered it. However, there is little value in doing so. Also, the wildly varying formats used to encode sub-cookies, sign them, encode them, etc. would make this task difficult...