Why does Safari not accept GZIP compression?

前端 未结 3 1844
孤独总比滥情好
孤独总比滥情好 2021-01-18 13:50

I have a pretty big JavaScript file here which I want to embed into my website. The HTTP server is smart enough to GZIP the file before delivering it to the browser.

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-18 13:53

    This is a while ago but I just came across a very similar issue or maybe the source of this issue. When you compress data with gzip for safari like this:

    gzip jquery.min.js
    

    You will end up with a jquery.min.js.gz which will fail in Safari even when correctly specified as gzip encoded file stream and also when renamed to jquery.jgz as mentioned in a lot of other threads about this issue. This seems to be because the filename is encoded in the gzip file.

    If you encode a gzip file like this:

    cat jquery.min.js | gzip > jquery.jgz
    

    Then you will have a file that is a few bytes smaller and does work flawlessly with Safari.

提交回复
热议问题