Search code examples
jqueryhttp-headerscompressiongzipgithub-pages

Can I serve gzipped JSON on GitHub Pages?


I have a JSON file on GitHub pages, it's about 2 MB uncompressed. I access that file via jQuery's $.get() method. I'd like to gzip the file, which shrinks it to about 500 KB, but when I put the gzipped file on GitHub pages, $.get() doesn't work with an error: Uncaught SyntaxError: Unexpected token

I think the problem is that GitHub pages doesn't set the Content-Encoding: gzip header on the JSON file, and the GET request thinks it's dealing with a plain JSON file. Is there any way to either:

  1. Force GitHub pages to add the Content-Encoding: gzip header to a .json file, OR
  2. Configure the AJAX request so that it knows it's dealing with a gzipped JSON file, even though the server hasn't told it that the content is zipped

Solution

  • Github pages is already gziping html, css, js, json,... It's useless to try to do better by gziping json yourself.

    A 1.3M json is sent as 357KB one by github pages. See here and click on "load json" link.