开发者

Is gzip an actual ZIP file?

开发者 https://www.devze.com 2023-04-12 15:32 出处:网络
Does a gzip contains an archive of the referenced assets, such as external JS, CSS, and images or does it only compress the one file?

Does a gzip contains an archive of the referenced assets, such as external JS, CSS, and images or does it only compress the one file?

If the browser ha开发者_如何学Gos never seen the site the before and has nothing cached then it seems like a good idea to send over an actual ZIP file that the browser unpacks. Is this how it’s done?

Update: Damn you Gzip! Why can't you unzip an actual ZIP?!


Only compress one file. You need to combine compression (e.g. gz, bz2 or xz) with an archive format (e.g. tar or cpio) to match ZIP's functionality (hence .tar.gz files).

Browsers pipeline multiple requests, they do not request a ZIP file. Browsers do rely on compression.

If you want to learn about this topic, look at the issues being solved by SPDY for a better understanding of the shortcomings of HTTP.


In case you mean web-server to web-browser communication. A webserver compresses the Response and the Browser decompresses it. But each Response will be compressed.

So in web-server to web-browser communication there will be no such thing like a multi-asset-compression.

In a more general case: GZIP compresses only "single files". You need to encapsulate them first in an archive format if you want to compress multiple files via gzip.


First, gzip is a compression algorithm, so it only compresses the data given (which doesn't have to be a file, any string is compressible with gzip), it doesn't archive multiple resources together (as opposed to ZIP, which does both archiving and compression, and operates on files).

Second, I have yet to see a browser which would support ZIP compression (although it's an interesting idea). The closest I've seen is the MHTML archive, which contains all the assets of one page; that could, in turn, be compressed with any algorithm; again, it is not universally supported.

Third, the usual way is to gzip-compress each response separately (be it HTML, JS, CSS, or whatnot - note that common image formats are already compressed, so you get no measurable benefit from compressing them again).


Gzip is not a container format like zip, it is just for compressing single files. Gzip combined with tar is used to create compressed directories like the zip format.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号