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 🙏

© 2025 – Pkg Stats / Ryan Hefner

fastify-minify

v1.2.0

Published

Minification and transformation plugin for Fastify

Downloads

44

Readme

fastify-minify

A plugin for Fastify to minify HTML, JS, JSON and CSS. And you can transform any response as your like.

Usage

const fastify = require("fastify")();

fastify.register(require("fastify-minify"), {
    cache: 2000,
});

fastify.get("/minfiedCSS", function (req, rep) {
    const css = getSomeCSS();
    rep.type("text/css").send(this.minifyCSS(css));
});

Three methods are added to the fastify instance. minifyHTML, minifyJS and minifyCSS (See transformers). All of them take a string as input and return a promise.

By default no response is minified automatically. You can enable it with global or minInfix.

Options

fastify.register(require("fastify-minify"), {
    cache: 2500,
    global: true,
    minInfix: (req, filePath) => req.query.mini === "true",
    validate: (req, rep, payload) => typeof payload === "string",
    htmlOptions: { caseSensitive: true },
    jsOptions: { "keep-classnames": true },
    cssOptions: {},
    transformers: [
        {
            suffix: "txt",
            contentType: "text/plain",
            func: value => value.toUpperCase(),
            decorate: "upperCaseText",
            useCache: false
        }
    ]
});

cache

  • Size of the lru-cache or a cache object with the functions set(string, string) and get(string)=>string | get(string)=>Promise<string>. quick-lru is used by default. It is used to cache the minification results.
  • default: 0
  • type: number | object

global

  • If truthy, every response with content type html, js or css (See transformers) will be minified. See validate.
  • default: false
  • type: boolean

minInfix

  • If truthy or a function (function(req, filePath)) that returns a truthy value, a new path for static files will be added with min-infix e.g. public/foo.min.css for public/foo.css. You need to have fastify-static installed to use it. The function is called onRequest. ❗ If you have static files with min-infix, they will be ignored.
  • default: false
  • type: boolean | function

validate

  • If this function (function(req, rep, payload)) returns a truthy value, the payload will be minified. It is called onSend and only if global or minInfix is enabled.
  • default: () => true
  • type: function

htmlOptions

jsOptions

  • An object that will be passed to terser.
  • default: {}
  • type: object

cssOptions

  • An object that will be passed to csso.
  • default: {}
  • type: object

transformers

  • An array of transformers to transform any response. There are 4 transformers built-in (JS, HTML, CSS, JSON).
    • suffix
      • Suffix of files to transform. Used when minInfix is enabled.
      • type: string | array of strings
    • contentType
      • Content type of response. Used when global or minInfix is enabled.
      • type: string | array of strings
    • func
      • Function to transform the response.
      • type: function (string => string | string => Promise<string>)
    • decorate (optional)
      • Method name of the decorated function.
      • type: string
    • useCache (optional)
      • If true, cache is used when transforming. Enabled by default.
      • type: boolean
    • To disable one of the built-in transformers you can add a transformer with respective suffix e.g. { suffix: "js", func: null }
  • default: []
  • type: array