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 🙏

© 2026 – Pkg Stats / Ryan Hefner

gab-astro-compress

v0.1.2

Published

Compression integration for static assets in astro, with caching.

Readme

NPM Downloads NPM Version

AstroCompress

A powerful compression integration for static assets in Astro. This package automatically optimizes and compresses various file types including images, HTML, JavaScript, CSS, and SVG files during the build process.

This integraton is inspired by astro-compress and I would like to thank Nikola Hristov for his excellent work. In my Astro project with hundreds of images, I found that the build time was too long. Because I had difficulty understanding the high level of abstraction in the original package, I decided to create my own solution. For small projects with few images, the original package is faster, but for larger projects with many images, this package is faster.

Features

  • 🖼️ Image optimization (PNG, JPEG, JXL, WebP, AVIF, HEIF, GIF, TIFF)
  • 📄 HTML minification
  • 🔧 JavaScript minification
  • 🎨 CSS minification
  • 📐 SVG optimization
  • 💾 Caching system for faster builds
  • ⚙️ Highly configurable compression settings

Installation

npm install gab-astro-compress

Usage

Add the integration to your astro.config.mjs:

import astroCompress from 'gab-astro-compress';

import { defineConfig } from 'astro';

export default defineConfig({
  integrations: [
    astroCompress({
      // optional configuration
    })
  ]
});

Note: gab-astro-compress hooks into the Astro astro:build:done hook. It is called when the static assets are finished. Add gab-astro-compress as the last integration for best results. This way it can also optimize the output of other integrations.

Configuration

You can customize the compression settings for different file types.

  • The compression for png, jpeg, jxl, webp, avif, heif, gif and tiff is handled by sharp. The gab-astro-compress integration wraps the corresponding sharp options, so that you have full control over the compression process.
  • The compression for html is handled by html-minifier-terser. The gab-astro-compress integration wraps the corresponding html-minifier-terser options, so that you have full control over the compression process.
  • The compression for js is handled by terser. The gab-astro-compress integration wraps the corresponding terser options, so that you have full control over the compression process.
  • The compression for svg is handled by svgo.
  • The compression for css is handled by csso.

The astro-compress integration wraps the corresponding tool options, so that you have full control over the compression process.

Below you can find the default configuration for each file type. The effort parameter is set to max for all image formats. As we are using a cache this will provide the best compression at reasonable build times. You can override the default settings in your configuration for faster builds.

export const defaultConfig: CompressOptions = {
    cache: {
        enabled: true,
        cacheDir: 'node_modules/.astro/.gab-astro-compress'
    },
    png: {
        compressionLevel: 9.0,
        palette: true
    },
    jpeg: {
        mozjpeg: true,
        trellisQuantisation: true,
        overshootDeringing: true,
        optimizeScans: true,
    },
    jxl : {
        effort: 9.0,
    },
    webp: {
        effort: 6.0,
    },
    avif: {
        effort: 9.0,
    },
    heif: {
        effort: 9.0,
    },
    tiff: {},
    gif: {
        effort: 6.0,
    },
    html: {
        collapseWhitespace: true,
        removeComments: true,
        minifyCSS: true,
        minifyJS: true,
        continueOnParseError: true
    },
    js: {
        compress: true,
        mangle: true,
    },
    svg: {
        multipass: true,
    },
    css: {}
};

Default Configuration

If no configuration is provided, the integration will use optimal default settings for each file type. You can override specific options while keeping the defaults for others.

Caching

The integration includes a caching system that stores compressed versions of files to speed up subsequent builds. Here's how it works:

  • Cache Storage: Compressed files are stored in a cache directory within the project's node_modules/.astro/.cache/compress folder.
  • Cache Manifest: A manifest file (manifest.json) keeps track of cached files, their original hashes, compression settings, and timestamps.
  • Cache Retrieval: Before compressing a file, the system checks if a cached version exists with the same original hash and settings. If found, the cached version is used.
  • Cache Invalidation: The cache is automatically invalidated when:
    • Source files change (detected via hash comparison).
    • Compression settings change (detected via settings comparison).
    • TODO: Cache version changes (indicating a new version of the integration).

File Types Supported

  • Images: .png, .jpg | .jpeg, .jxl, .webp, .avif, .heif, .gif, .tiff | .tif)
  • HTML: .html, .htm
  • JavaScript: .js, .cjs, .mjs
  • Stylesheets: .css
  • Vector Graphics: .svg

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Issues

If you find a bug or want to request a new feature, please open an issue on GitHub.

Acknowledgments

This is a fork of mysong-compress, thanks for the original creator @mysongstudio !

License

MIT