Is there a way to enable CORS on Github pages?

Daniel X Moore picture Daniel X Moore · Sep 20, 2013 · Viewed 8.3k times · Source

I'm hosting some JSON files on Github pages, but I am unable to use $.getJSON to retrieve them unless they come from the exact same domain.

Is there a way to enable CORS for Github pages?

Answer

Daniel X Moore picture Daniel X Moore · Sep 20, 2013

As a workaround one can use JSONP, but it's still slightly a pain because the files are static, and each one will need a unique callback method.

Another alternative would be to store the files in Gists and use the Github API which works with CORS.

A third possibility is to not store the files on Github pages and instead host them on an S3/Cloudfront distribution with CORS enabled.