Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

astro-compressor

sondr348.3kMIT1.0.0TypeScript support: included

A gzip and brotli compressor for Astro

astro, astro-integration, astro-component, performance

readme

astro-compressor

GitHub Actions Status npm version

A gzip and brotli compressor for Astro

  • Simple: Set it and forget it
  • Optimal: By compressing ahead of time, a more performant compression can be performed
<summary>Table of Contents</summary>

Table of Contents

NOTE

  1. Important: It is important that this is the last integration in the integrations property to ensure all the generated files are compressed.
  2. Note: This only works for static exports, SSR does not export assets that can be compressed ahead of time so you need to solve it with middleware. See this for more context and a partial solution.

Quickstart

Install via your tool of choice:

# Using NPM
npx astro add astro-compressor
# Using Yarn
yarn astro add astro-compressor
# Using PNPM
pnpm astro add astro-compressor

To compress your files, simply run pnpm build and look for the compression messages in the build log.

Usage

First, install the package with your favorite package manager: pnpm add --dev astro-compressor, then configure it in your astro.config.* file in the integrations property:

import { defineConfig } from "astro/config";
import compressor from "astro-compressor";

export default defineConfig({
  // ...
  integrations: [..., compressor()],
});

Configuration

You can also optionally enable and/or disable either the gzip or brotli compression by passing an options object to the compressor:

import { defineConfig } from "astro/config";
import compressor from "astro-compressor";

export default defineConfig({
  // ...
  integrations: [..., compressor({ gzip: true, brotli: false })],
});

Or customize the file formats that will be compressed:

import { defineConfig } from "astro/config";
import compressor from "astro-compressor";

export default defineConfig({
  // ...
  integrations: [..., compressor({
    fileExtensions: [".html"] // only compress HTML files
  })],
});

By default the fileExtensions array is [".css", ".js", ".html", ".xml", ".cjs", ".mjs", ".svg", ".txt"].

License

MIT.

changelog

v1.0.0

2024-11-28

Summary

The main change is that the compression is now batch parallelized to speed up compression for larger sites and the custom logger was replaced with the Astro logger. Bumped packages and moved from ESLint/Prettier to Biome.

Commits

  • [8892cf1] Use AstroIntegrationLogger over custom logger
  • [4853f21] Update README
  • [2b9a0ab] Run CI against latest and LTS NodeJS
  • [2150125] Extract out compression login to shared function
  • [e7bc27d] Parallelize and batch process files
  • [8c56e05] And run correct lint tasks in CI
  • [18cdd9c] Use pnpm@9 in CI
  • [3d55b57] Bump remaining packages
  • [b2ed13e] Bump typescript, use @tsconfig/bases packages for config
  • [e28eb3a] Add test step to CI
  • [ce437bd] Add a test site to run integration tests against
  • [0db2b37] Remove prettier and eslint, move to biome
  • [f125d43] Bump pnpm/action-setup from 3.0.0 to 4.0.0
  • [633c1a9] Bump pnpm/action-setup from 2.4.0 to 3.0.0
  • [ec3bff9] Bump actions/setup-node from 3 to 4

v0.4.1

2023-09-29

Summary

Documentation updates, no functional changes.

Commits

  • [7750c7e] Add note about SSR not working
  • [ac15c66] Bump actions/checkout from 3 to 4
  • [7099290] Bump pnpm/action-setup from 2.3.0 to 2.4.0
  • [e554525] Bump pnpm/action-setup from 2.2.4 to 2.3.0
  • [ad26a44] Add defaults for fileExtensions to README

v0.4.0

2023-03-20

Summary

Add configurable file extensions to options, allowing the user to change the default files that are compressed.

Commits

  • [02181b8] Add file extension configuration to README
  • [4015722] Make compressed file extensions configurable
  • [f3355d1] Bump dependencies
  • [53f98e7] Bump packages
  • [102fe95] Cache prettier

v0.3.0

2023-01-31

Summary

Add configuration options to integration, bump Astro dependency to 2.0.

Commits

  • [bf612b4] Add configuration to README
  • [230e092] Bump packages
  • [3472d07] Allow enabling/disabling gzip and brotli compression
  • [711a36f] Prefix url with node:

v0.2.2

2022-12-29

Summary

Fix paths for Windows.

Commits

  • [d9d04eb] Use fileUrlToPath to fix path on Windows
  • [cef27ed] Don't force height on badge
  • [2fbaa34] Use shields.io over badge.fury.io
  • [a0f7ba1] Update version badge

v0.2.1

2022-12-29

Summary

Spelling fix and file name filtering change.

Commits

  • [fc44e2a] Use extname to get file extension
  • [341fd5c] Change m -> ms

v0.2.0

2022-12-29

Summary

Removal of dependency over using the node standard library.

Commits

  • [f0840e5] Remove globby dependency, use stdlib

v0.1.3

2022-12-27

Summary

Update dependencies, fix some CI steps.

Commits

  • [28b0d90] Fix release CI step
  • [acc0b18] Update dependencies, fix formatting
  • [8a64bff] Add publish step on CI pipeline

v0.1.2

2022-08-28

Summary

Fix wording in README.

Commits

v0.1.1

2022-08-27

Summary

Quick bugfix release for a stray console.log that was left accidentally.

Commits

v0.1.0

2022-08-27

Summary

Initial relase of a gzip and brotli compressor for Astro.

Commits

  • [0067f9c] Fix compression
  • [5b821f3] Add compression logic
  • [bfd7439] In the beginning there was darkness