The optional @loaders.gl/polyfills
module installs support for Node.js and older browsers.
loaders.gl is based on the HTML5 API provided by modern, evergreen browsers. Older browsers (mainly Edge and IE11) as well as versions of Node.js prior to v12 do not provide certain classes that loaders.gl depends on.
Note that while @loaders.gl/polyfills
is designed to work seamlessly with other loaders.gl modules, using it is not a requirement. There are other good polyfill modules available on npm
that can be used in its place.
npm install @loaders.gl/polyfills
Just import @loaders.gl/polyfills
before you start using other loaders.gl modules.
import '@loaders.gl/polyfills';
import '@loaders.gl/core';
To use the experimental Blob
and File
polyfills
import {installFilePolyfills} from '@loaders.gl/polyfills';
installFilePolyfills();
Polyfill | Node | Browser | Comments |
---|---|---|---|
TextEncoder /TextDecoder | Node.js < 11 | Yes (Older browsers) | Only UTF8 is guaranteed to be supported |
atob /btoa | All versions | No | Note: these functions are not unicode safe, but OK to use for test cases. |
fetch | All versions | No | A subset of the fetch API is supported, see below. |
Response | All versions | No | A subset of the Response API is supported, see below. |
Headers | All versions | No | A subset of the fetch API is supported, see below. |
Blob (Experimental) | All versions | No | A subset of the fetch API is supported, see below. |
File (Experimental) | All versions | No | A subset of the fetch API is supported, see below. |
FileReader (Experimental) | All versions | No | A subset of the fetch API is supported, see below. |
ReadableStream (Experimental) | All versions | No | A subset of the ReadableStream API is supported. |
The Node.js fetch
, Response
and Headers
polyfills supports a large subset of the browser fetch API, including:
Response.text()
, Response.arrayBuffer()
, Response.json()
Response.body
streamheaders
, status
, statusText
etc.content-encoding
headers..gz
are automatically decompressed with gzip decompression (this is only done on Node.js, in the browser the content-encoding header must be set).The Node.js fetch
is able to follow 30X redirect: if Response
has status 300-399 and location
header is set, the fetch
polyfill re-requests data from location
.
TextEncoder
and TextDecoder
polyfills are provided to ensure these APIs are always available. In modern browsers these will evaluate to the built-in objects of the same name, however under Node.js polyfills are transparently installed.
Note: The provided polyfills only guarantee UTF8 support.
Header
polyfill (for Node.js fetch
) is a fork of the implementation in https://github.com/github/fetch (MIT license).Blob
and File
polyfills are forks of @gozala's web-blob
and web-file
modules respectively, under MIT license.