提供gzip压缩文件时要使用什么'Content-Type'标头? [英] What 'Content-Type' header to use when serving gzipped files?

查看:1724
本文介绍了提供gzip压缩文件时要使用什么'Content-Type'标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在提供我的css / javascript文件的gzipped副本。根据教程,我在提供这些文件时将内容类型设置为 application / gzip 。但是,chrome似乎不会解压缩这些文件,而对于javascript文件,我会收到很多非法字符错误。如果我查看源代码,我仍然看到文件是压缩的,而不是未压缩的。

I'm serving gzipped copies of my css / javascript files. As per a tutorial, I set the content-type as application/gzip when serving these files. However, chrome doesn't seem to un-gzip these files, and for the javascript files I get a lot of 'illegal character' errors. If I view source, I still see the files as compressed, rather than uncompressed.

我的问题是,我应该将这些文件的内容类型设置为什么,按顺序浏览器将它们正确解释为gzip压缩的css / js文件,并取消gzip它们?如果我只设置 text / javascript text / css ,浏览器是否仍会正确解释它们?

My question is, what should I set as the content type for these files, in order for the browser to interpret them correctly as gzipped css / js files, and un-gzip them? If I just set text/javascript or text/css, will the browser still interpret them correctly?

编辑:完整回复标题:

HTTP/1.1 200 OK
x-amz-id-2: UIBkZT/MuFxsmn+3nVOzEO63rRY99l3traCbMExUgSdGHUrOIPtNp34h1+ujYKmt
x-amz-request-id: 19346C9B01D8FC62
Date: Mon, 12 May 2014 03:59:51 GMT
Content-Encoding: gzip
Last-Modified: Mon, 12 May 2014 02:24:54 GMT
ETag: "561080b5e19f6daea2e74fd5a0623c79"
Accept-Ranges: bytes
Content-Type: application/x-gzip
Content-Length: 5153
Server: AmazonS3


推荐答案

响应中的压缩内容显示在 Content-Encoding 中。 Content-Type 应该保持不变,也就是说,它应该反映压缩的基础媒体类型。

Compressed content in the response is indicated in the Content-Encoding. The Content-Type should remain the same, that is, it should reflect the underlying media type that is compressed.

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

请参阅 14.11内容编码 3.5内容编码 RFC 2616获取更多信息。

See sections 14.11 Content-Encoding and 3.5 Content Codings of RFC 2616 for more information.

这篇关于提供gzip压缩文件时要使用什么'Content-Type'标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆