A gzip and brotli compressor for Astro
MIT License
integrations
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
Then, restart the dev server by typing CTRL-C
and then npm run dev
in the terminal window that was running Astro.
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()],
});
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"]
.
MIT.