I need to effectively access a large gzipped xml file from javascript (actually from Greasemonkey). Unfortunately, the server does not contain the Content-Encoding header, and the Content-Type does not contain "application / x-gzip", so firefox will not (as far as I can tell) automatically inflate it. If there is a way to fake firefox, that would be ideal. In short, I need some way to effectively make inflation ... what I'm using now takes about 30 seconds to blow off a file with a 1.2 Mb file size; I would like to receive it in less than 5 seconds.
(The Greasemonkey script I work, I have no other external dependencies on the server, so proxying and presenting the Content-Encoding header is not an option.)
What I am doing now, I have secured from several places. To get binary data unchanged, I use the firefox extension XMLHTTPRequest overrideMimeType :
$.ajax(url, { dataType:'text', beforeSend:function(xhr){ xhr.overrideMimeType('text/plain; charset=x-user-defined') }, success:function(data){ var blob=''; for (i=0; i<data.length; ++i) blob += String.fromCharCode(data.charCodeAt(i) & 0xff); ...
Then bloat using a slightly modified and built-in copy of https://github.com/dankogai/js-deflate/blob/master/rawinflate.js (there are a few other javascript extensions too, everything is there as I can tell from the old http: / library /www.onicos.com/staff/iz/amuse/javascript/expert/inflate.txt ). This is a terribly slow part.
// blithely assuming the gzip header won't change, // strip a fixed number of bytes from the front deflated=RawDeflate.inflate(blob.substring(22,blob.length-8));
Then enter it in the innerHTML property to parse it:
xmlcontainer=$('<div>');
(I know that the last bit can be more correctly executed using the DOMParser parseFromString, but I have not received this yet.)
source share