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

@gera2ld/fallback-js

v1.0.0

Published

Set up fallback messages easily

Downloads

6

Readme

@gera2ld/fallback-js

NPM License

Set up fallback messages easily when browser fails running essential scripts.

Why

In case you have an application targeting the latest browsers, you may need to notify users to upgrade their browsers if they are using an obsolete one. With this script you can easily set up a notice when essential scripts fail.

Basic Usage

  1. Add necessary elements

    <div id="main">
      This is the main application.
    </div>
    
    <div id="fallback-js" style="display: none" data-hide="#main">
      <h1>Oops</h1>
      <p>Unfortunately, your browser is too old to work for this application. Please upgrade your browser.</p>
    </div>
    <!-- Run fallback-js first -->
    <script src="https://cdn.jsdelivr.net/npm/@gera2ld/fallback-js"></script>
    
    <!-- Run your main script after -->
    <script src="app.js"></script>
  2. Be sure to call FallbackJs.ok() after your main script (app.js here).

    // app.js
    // ...
    
    // call ok at the end
    FallbackJs.ok();

Advanced Usage

Configurations can be overridden by assigning to window._fallbackJs before running fallback-js.

<script>window._fallbackJs = {
  debug: true,
  onError: function (errors) {
    console.error(errors);
  },
};</script>
<script src="https://cdn.jsdelivr.net/npm/@gera2ld/fallback-js"></script>

Available configurations are:

  • debug: boolean, default as false

    Whether to show debug messages.

  • selector: string, default as '#fallback-js'

    If an element is found by document.querySelector(selector), it will be shown when essential scripts fail.

  • timeout: number, default as 1000

    Time to wait until FallbackJs.ok() is called.

  • count: number, default as 1

    The number of scripts that are supposed to run successfully and call FallbackJs.ok().

  • hide: string, default as null

    If specified and an element is found by document.querySelector(hide), it will be hidden once scripts fail.

  • onError: function, default as null

    Once scripts fail, errors will be passed to this callback. It is useful if you want to show the error details.