Nitro now has an option compressPublicAssets which can be used in nuxt3. Please consider using that. https://nitro.unjs.io/config#compresspublicassets
This is an unofficial compression module for Nuxt 3. Currently it only works with vite. It uses vite-plugin-compression to generate the compressed files. To make this work and serve those files, this plugin modifies the internal code of the unjs/nitro package. There is already an issue for an official way to implement some kind of compression which you can check out here.
yarn install -D @averjs/nuxt-compression
pnpm add -D @averjs/nuxt-compressionexport default defineNuxtConfig({
buildModules: ['@averjs/nuxt-compression'],
'compression': {
// options
},
});- default -
{
algorithm: 'brotliCompress',
filter: /\.(js|mjs|json|css|html)$/i
}Options for the vite-plugin-compression plugin
- default -
60 * 60 * 24 * 365
Set the maxAge for the Cache-Control Header. Can either be a number or a filter function which accepts the asset path and should return a number. Be aware, if you use cacheControl alongside maxAge, it is getting ignored.
- default -
undefined
Set Cache-Control Header. Can either be a string or a filter function which accespts the asset path and should return a valid Cache-Control Header string. This option has more weight than maxAge and overwrites it. You can head to MDN to see all the available options.
- Run
pnpm dev:prepareto generate type stubs. - Use
pnpm devto start playground in development mode.