To get started, clone and build the service. Polyfill Service is available in two flavors, as a Java API or RESTful API. With the Java API, you can customize how you want to fetch polyfills and even narrow down which polyfills to fetch. The REST API provides endpoints for you to work with different URL variables and query parameters. Both APIs fulfill the following conditions:
We recommend exploring both services to see what works best for your project. Although both services are considered lightweight and performant, the Java API is ideal if you already know which polyfills you want to include or eliminate, and you don't want to make an extra request.
This picture is far from ideal. We need a better way to only load polyfills when they are needed. And this is where Polyfill Service shines.
Is that the most efficient way? The problem is that we are forcing modern browsers to run old code when they don’t have to. They understand ES6. Why not just give them ES6?
Note: One thing to be clear, Polyfill Service does not provide support for syntactic sugar. For example, Classes, enhanced Object Literals, and things like Arrow Functions. You'd still need a compiler for those.
Essentially, what we want from a polyfill delivery system is a way to send a single copy of each of the best polyfills, in the right order (respecting dependencies), to just the browsers that lack a native implementation. The polyfill service does this by parsing the User-Agent from HTTP header and then using it to find the list of polyfills that are suitable for that browser and its specific version.
Note: Typically once a browser version is released, its feature set does not change until its next release.
Clone and build the project
$ git clone https://github.com/reiniergs/polyfill-service.git $ cd polyfill-service $ mvn clean install
Start the app server
$ mvn jetty:run -pl web
After the server starts up, navigate to
http://localhost:8080 to test that it is up
$ mvn test # run unit tests $ mvn verify -Pintegration-test # run integration tests
Start the app server and navigate to
This service uses the polyfill.io
npm package for a set of polyfills and their metadata. We welcome original polyfills or third party polyfills as well.
Polyfills are located in the
/polyfill-service-api/polyfills directory and each folder represents a feature. The subdirectories follow the convention for polyfill.io. For example,
/polyfill-service-api/polyfills/Array/prototype/forEach should be used to hold the polyfill for
See Authoring Polyfills for more information on: