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

tailwindcss-noscript

v2.0.1

Published

Conditionally apply Tailwind styles when JavaScript is enabled.

Downloads

15

Readme

TailwindCSS <noscript>

Apply Tailwind styles only when JavaScript is enabled.

Why

When animating an element above the fold with JavaScript, the default styles of the element may be briefly visible before JavaScript loads and applies the initial animation styles. Something as simple as fading-in the opacity of an element requires to either…

  • Settle with an ugly flash of opaque content (🤢)
  • Make the initial animation styles the default ones and disappoint your non-JavaScript-using visitors (😕)
  • Go with the previous option and manually reset the styles with a noscript tag (🤮)

Going with the noscript approach with tailwindcss can be quite cumbersome. This plugin can be used as an alternative method to maintain ergonomics in exchange for a minuscule amount of render-blocking JavaScript.

Installation

npm i tailwindcss-noscript
# OR
yarn add tailwindcss-noscript
# OR
pnpm i tailwindcss-noscript

Usage

Add the plugin to the plugins array in your tailwindcss configuration file:

import type { Config } from "tailwindcss"
import noscriptPlugin from "tailwindcss-noscript"

export default {
  // ...
  plugins: [
    // ...
    noscriptPlugin,
  ]
} satisfies Config

You now need to add a script tag to your head with the following content:

import { script } from "tailwindcss-noscript"

<script src={script} />

If you are working with vanilla HTML, you can also copy and paste it:

<script src="data:text/javascript;base64,KGZ1bmN0aW9uKCl7ZG9jdW1lbnQuZG9jdW1lbnRFbGVtZW50LmNsYXNzTGlzdC5hZGQoImpzIik7fSgpKQ=="></script>

That's it. You can now add JS-only styles using the js variant prefix:

<div src="js:opacity-0 js:translate-y-1/2 md:js:translate-y-full" />

Note When applying multiple variants, place the js prefix in the last place.

Acknowledgements

  • next-themes
    The mechanism to prevent CLS was inspired by next-themes. I also took the idea of compressing the script with base64 from next-real-viewport (the folks at Basement Studio make lovely things 💖).