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.

Why is .js.gz file not being served?

See original GitHub issue

I gzipped my app.js to app.js.gz and then ran http-server -g, as specified in the readme of this website.

But my browser still receives the .js file, not the .js.gz file, as you can see in the screenshot. Is this is a bug?

untitled

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:22 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
the0neWhoKnockscommented, Jul 10, 2018

@thescientist13 as I stated above, it worked if you generated your own gz files. The issue I was having was that if I enabled/passed a flag saying “turn gzip on”, I was expecting the server to do the gzip’ing on the fly. I’m fine with generating the files manually (now that I know that’s what I was supposed to do). It was just frustrating at the time since I wasted time thinking it was user error. Really what the --gzip flag does, is say “if a gz version of a file exists, I’ll use that instead” - not “I’ll now gzip and serve specified file types”.

7reactions
the0neWhoKnockscommented, Oct 31, 2017

I’m running 0.10.0, looks like the gzip PR’s in there, but I’m still not seeing gzipped content come through. I’m running http-server ./build --gzip -o -p 8080.

After reading through ecstatic’s docs, https://www.npmjs.com/package/ecstatic#optsgzip led me to what @RichardJECooke tried (to manually create a .gz file). After doing so, I’m seeing that file served.

The confusion seems to come from the fact that most servers that have a “simple setup” (and gzip is one of the available options), the server will do the work of gzipping for you (which is what I expected). This should really be called out in the docs to lessen confusion.

Possible solutions to anyone that come across this issue:

  • Ask the ecstatic folks to update the middleware function to utilize the built in zlib module so files get automagically served up gzipped.
  • If you’re utilizing WebPack to build out assets, you can use the CompressionPlugin to generate the .gz files at build time with a configuration like this
new CompressionPlugin({
  asset: '[path].gz[query]',
  algorithm: 'gzip',
  test: /\.js$|\.css$|\.html$/
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Gzipped javascript not being served properly - Stack Overflow
I have encountered problems with some browsers (notably Safari) not dealing appropriately when the file name extension was ".gz".
Read more >
(html gzip) files seem to not be served - WordPress.org
When the “Pre-compression of cached pages. Needs to be disabled if the decoding fails in the web browser” option is active, you *normally* ......
Read more >
Point next export .html files at .js.gz files : r/nextjs - Reddit
I'm serving a nextjs app over CDN(no server) and I'm generating gzipped js files with ` compression-webpack-plugin`. But the .js.gz files ...
Read more >
Serve Pre-Compressed CSS/JS Files - WP Rocket
But the pre-compressed files will not be served automatically due to the possibility of server conflicts. If you want to take advantage of...
Read more >
How to use a gzip javascript file in a webapp running under ...
if not how to send a gzip javascript file to browser? any help would be ... your gzip'd CSS file and serves it...
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