Skip to content

Commit

Permalink
xhr fastpast
Browse files Browse the repository at this point in the history
  • Loading branch information
samthor committed Apr 28, 2020
1 parent 60eceba commit 2489b7e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
10 changes: 5 additions & 5 deletions text.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,15 @@ function decodeBuffer(bytes) {
* @return {string}
*/
function decodeSyncXHR(bytes) {
const b = new Blob([bytes]);
const b = new Blob([bytes], {type: 'text/plain;charset=UTF-8'});
const u = URL.createObjectURL(b);

// This hack will fail in non-Edgium Edge because sync XHRs are disabled (and
// possibly in other places), so ensure there's a fallback call.
try {
const x = new XMLHttpRequest();
x.open('GET', u, false);
x.send(null);
x.send();
return x.responseText;
} catch (e) {
return decodeFallback(bytes);
Expand Down Expand Up @@ -239,9 +241,7 @@ if (typeof Buffer === 'function' && Buffer.from) {
} else if (typeof Blob === 'function' && typeof URL === 'function' && typeof URL.createObjectURL === 'function') {
// Blob and URL.createObjectURL are available from IE10, Safari 6, Chrome 19
// (all released in 2012), Firefox 19 (2013), ...

// TODO(samthor): I should probably check that this hack works in IE10 before shipping it.
// decodeImpl = decodeXHR;
decodeImpl = decodeSyncXHR;
}

/**
Expand Down
11 changes: 6 additions & 5 deletions text.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions text.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2489b7e

Please sign in to comment.