https://github.com/sondr3/astro-compressor
A gzip and brotli compressor for Astro
https://github.com/sondr3/astro-compressor
Last synced: about 2 months ago
JSON representation
A gzip and brotli compressor for Astro
- Host: GitHub
- URL: https://github.com/sondr3/astro-compressor
- Owner: sondr3
- License: mit
- Created: 2022-08-27T22:05:50.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-02-07T13:48:32.000Z (5 months ago)
- Last Synced: 2025-04-12T18:52:10.768Z (3 months ago)
- Language: Astro
- Homepage:
- Size: 271 KB
- Stars: 97
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
astro-compressor
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 performedTable of Contents
## Table of Contents
- [Quickstart](#quickstart)
- [NOTE](#NOTE)
- [Usage](#usage)
- [Configuration](#configuration)
- [License](#license)# 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](https://github.com/sondr3/astro-compressor/issues/13#issuecomment-1739721634)
for more context and a partial solution.# Quickstart
Install via your tool of choice:
```sh
# 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:```js
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:```js
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:
```js
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.