Serve assets with compression
See original GitHub issueEnvironment
- Operating System:
macOS
- Node Version:
v16.14.0
- Nitro Version:
0.2.1
- Package Manager:
yarn@3.1.1
Reproduction
n/a
Describe the bug
It would be a nice addition to nitro if there is be a possibility to change the response of static assets. Then it would also be possible to implement content encoding like brotli
or gzip
.
Additional context
There does exist a discussion in the nuxt repo. https://github.com/nuxt/framework/discussions/3472
In addition to the discussion i already found the corresponding lines, which i changed in nuxt, in the nitro package:
https://github.com/unjs/nitro/blob/main/src/runtime/static.ts#L68 https://github.com/unjs/nitro/blob/main/src/rollup/plugins/public-assets.ts#L44
Logs
No response
Update 21.07.2022
I wrote a module which can handle the compression https://github.com/exreplay/nuxt-compression. This is still no official way and messes with the internal nitro code but there is no need to use patches.
Issue Analytics
- State:
- Created a year ago
- Reactions:11
- Comments:26 (12 by maintainers)
Top GitHub Comments
I found another way to make all this work without the need for a patch and everything else. I wrote a module real quick for everyone to use. You can find the package here https://github.com/exreplay/nuxt-compression. I already tried it locally and in my production environment with success.
Hi there and sorry it took long to add this feature.
Generally, I would recommend you use a CDN that can natively support compression. It is much more efficient to handle best compression with long term caching.
#449 adds a new option
compressPublicAssets
that can be optionally enabled to enable compression (feedback and improvements more than welcome 🙏🏼)To enable this option for Nuxt 3, use edge channel (or wait for rc.9) and: