Assuming a server which cannot zip responses to user requests. A web developer nevertheless creates a myfile.txt.gz
and stores it at http://www.mysite.com/myfile.txt.gz
.
It is possible to have the browser automatically gunzip this compressed text file as part of the Ajax request and store the result in a var
? If yes, how?
I am open to other compression algorithms if necessary.
Update
I am trying to use the following JQuery Ajax call:
var fetch = function() {
$.ajax({
type: 'GET',
url: "./data.txt.gz",
headers: { "Accept-Encoding" : "gzip" },
dataType: "text",
async: true,
success: function(result) {
$("#midEnglob").text(result);
},
error: function(jqXHR, textStatus, errorThrown) {
alert("Issue: "
+ textStatus + " "
+ errorThrown + " !");
}
});
}
but I get the following in my browser:
Any ideas?
letting the browser uncompress it with Content-Encoding: gzip is probably the best. In case it doesn't work for your scenario, there are many LZW implementations in javascript like: https://gist.github.com/revolunet/843889
you might have to try out different implementations, i didn't check any of them myself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With