提供 gzip 文件时使用什么“Content

编程入门 行业动态 更新时间:2024-10-07 00:13:04
本文介绍了提供 gzip 文件时使用什么“Content-Type"标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在提供我的 css/javascript 文件的 gzip 副本.根据教程,我在提供这些文件时将内容类型设置为 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 文件并解压缩它们?如果我只设置了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

本文发布于:2023-11-25 06:19:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628648.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   gzip   Content

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!