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.
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?
Edit: Full response headers:
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
"gzip" is often also used to refer to the gzip file format, which is: a 10-byte header, containing a magic number ( 1f 8b ), the compression method ( 08 for DEFLATE), 1-byte of header flags, a 4-byte timestamp, compression flags and the operating system ID.
you need to unchank it. ... if ($chunked) $body=http_unchunk($body); if ($gzip) $body=gzdecode($body); if ($deflate) $body=gzdeflate($body); ...
The Accept-Encoding request HTTP header indicates the content encoding (usually a compression algorithm) that the client can understand. The server uses content negotiation to select one of the proposals and informs the client of that choice with the Content-Encoding response header.
The Content-Encoding representation header lists any encodings that have been applied to the representation (message payload), and in what order. This lets the recipient know how to decode the representation in order to obtain the original payload format.
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
See sections 14.11 Content-Encoding and 3.5 Content Codings of RFC 2616 for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With