I'm fetching some JSON with angular as:
$http({
url: '',
method: "GET",
params: {}
}).success(function(data, status, headers, config) {
console.log(data);
}
The data it's receiving is quite large, and I'm happy to gzip the source but is there a way to gunzip it when my $http
method fetches it?
I'm fetching some JSON with angular as:
$http({
url: 'https://www.somemachine./getdata',
method: "GET",
params: {}
}).success(function(data, status, headers, config) {
console.log(data);
}
The data it's receiving is quite large, and I'm happy to gzip the source but is there a way to gunzip it when my $http
method fetches it?
1 Answer
Reset to default 6Assuming the source is already zipped, just ensure the Accept-Encoding header is set to gzip on the request:
$http.get('https://www.somemachine./getdata', { headers: { 'Accept-Encoding': 'gzip' } }
).success(function(data, status, headers, config) {
console.log(data);
});
The browser will automatically unzip it when it sees the Content-Encoding=gzip header on the response.