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.

Wrong 'Content-Type' when retrieving gzip:ed js

See original GitHub issue

While running CherryPy 10.0, I encounted an issue while trying to retrieve some gzipped javascript. In order to save space on an embedded device, I’m only installing the *.js.gz files, not the unpacked *.js. After changing our html to directly request the *.js.gz files, the webapp stopped working.

CherryPy is configured to server those files by enabling tools.staticdir.on The reason is that CherryPy sets ‘Content-Type: application/x-gzip’ when retrieving those files. I believe that CherryPy should set:

Content-Type: application/json
Content-Encoding: gzip

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jaracocommented, Feb 10, 2017

I believe that CherryPy should set…

I’d feel better if I had more than one user’s expectation that the headers should be as you propose, either a reference to a standard or documentation showing these headers are what a browser would expect or simply existing behavior in another more popular web server (like nginx).

Looking at the docs for Content-Encoding, it is used to indicate an additional encoding of the entire body. In the case of serving a single file, the entire body is the file, which may be why your technique works, but it’s confusing. Your tricking the client into thinking they’re getting a Javascript file that’s been encoded using gzip, rather than serving the gzip file directly. My guess is with this proposal implemented, if you were to curl that file, you’d get a file.js.gz file on your disk containing uncompressed javascript, and that’s definitely not what you’d expect.

This proposed change also has the potential to interact badly with other behavior, like the gzip tool. Any change would necessarily need to document or test what is expected in such conditions.

After changing our html to directly request the *.js.gz files, the webapp stopped working.

Do you have reason to expect that HTML is able to request gzipped js files? If your app doesn’t work on other web servers, then it shouldn’t magically work on CherryPy either, unless…

Perhaps what you should consider is writing a custom tool for CherryPy that does exactly what you’re after - serving file.js.gz as file.js with gzip encoding. Then, your app could request ‘file.js’ and the server would serve the already gzipped encoding as you’ve described. You get the space saving on your embedded device and the browser gets javascript as it expected.

I can see some situations where this behavior should be the default for CherryPy, but only if that’s consistent with the expectation from other web servers. Otherwise, this behavior should be a separate, opt-in tool.

0reactions
darandercommented, Feb 10, 2017

I’m reopening this issue, this time I’ve modified my problem description to:

Let the device have both *.js and *.js.gz files. However, to save space, make all *.js be empty. This should work, as long as the browser accepts gzip-ed files.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gzipped javascript sends wrong Content-Type response ...
I am able to resolve this by adding Header set Content-Type text/javascript to my .htaccess file beneath "Header append Vary Accept-Encoding" ...
Read more >
require() on gzip'd file returning wrong-MIME-type error
In Chrome and Firefox I get this error: Resource interpreted as Script but transferred with MIME type application/x-gzip: "http://sample.com/ ...
Read more >
Javascript files are not getting compressed (gzip) - Jira
Since Bitbucket 6.10.3 application/javascript MIME type files are not getting compressed by Bitbucket before being sent to the client.
Read more >
How to Enable GZIP Compression to Speed Up WordPress Sites
Learn how to enable GZIP compression to speed up your WordPress site on various web servers like Apache, Nginx, and IIS.
Read more >
Serving compressed files - Amazon CloudFront
You can use CloudFront to automatically compress certain types of objects ... that the object is compressed based on the presence of a...
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