Cross-origin requests on Google CDN

I am trying to download a .json file from Google CDN:

//ajax.googleapis.com/ajax/libs/dojo/1.8/dojox/geo/charting/resources/data/USStates.json

Standard xhr requests are not executed due to cross origin policy. Does Google CDN support any cross-search request, such as JSONP or CORS? Could you show me an example of how to capture the above file?

This file is part of Dojo, but I'm fine using any other library or regular JavaScript. The only limitation is to grab the file from the Google CDN.

+4
source share
3 answers

Based on the (lack of) information I received, Google CDN does not support any cross-domain access, such as JSONP or CORS. This means that the only way to consume CDN.json files is through a proxy server.

For client-side JavaScript, I will need to save a local copy of the file.

+1
source

It doesn't seem to be that way:

$.ajax('//ajax.googleapis.com/ajax/libs/dojo/1.8/dojox/geo/charting/resources/data/USStates.json'). then(function(data) { console.log(data) }) // {"layerExtent": …} 
0
source

I know it has been a long time since this question was asked, but now the google repository allows us to change CORS configurations.

I had the same problem with CORS, and I took the following steps to solve it.

  • Create a JSON file with CORS configurations cors-config.json
 [ { "origin": ["*"], "method": ["GET"], "maxAgeSeconds": 3000, "responseHeader": ["Authorization", "Content-Range", "Accept", "Content-Type", "Origin", "Range"] } ] 

2. Download this file to the trash

 gsutil cp cors-config.json gs://[bucket_name] 

3. Now update the cors bucket configuration

 gsutil cors set cors-config.json gs://[bucket_name] 

Updated CORS configurations. Now you can see the updated CORS configurations in the bucket by running this command.

 gsutil cors get gs://[bucket_name]/ 

Google Doc on CORS Configuration

0
source

Source: https://habr.com/ru/post/1440142/


All Articles