question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Serve assets with compression

See original GitHub issue

Environment

  • 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:closed
  • Created a year ago
  • Reactions:11
  • Comments:26 (12 by maintainers)

github_iconTop GitHub Comments

20reactions
exreplaycommented, Jul 21, 2022

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.

5reactions
pi0commented, Aug 30, 2022

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:

defineNuxtConfig({
 nitro: { compressPublicAssets: true }
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Serving compressed static assets with HTTP in Go 1.16
Recommended way of embedding assets is to compress them before the build, so that binary includes *.gz or *.br files. This can be...
Read more >
Express: Serve pre-compressed static assets - node.js
I'd like to pre-compress my static assets (excluding images) and serve them. To serve the public folder, I have: app.use(express ...
Read more >
Improve Your Web App Performance By Serving Static Files in ...
So I tried to do some research for static files (text) compression. And then I knew that almost all browsers support for accepting...
Read more >
Pre-compress static assets with Brotli and Gzip
Pre-compressing static assets reduces the CPU load of your server and avoids to compress static files upon each an every request.
Read more >
Beyond the Basics - Optimizing Asset Files with Compression
Now if we run heroku local or npm run prod and open it in our browser, we can see the gzip files are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found