Skip to content
Switch branches/tags
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Build Status

polyfill-lambda is a service deployed to Amazon Web Services that returns JavaScript polyfills based on the user agent of the requesting browser. You can use this package to deploy your own version for your service or organization.

Getting started

Ensure you have node and yarn installed.

  1. Run yarn in the root of the repository to get the dependencies.
  2. Create a src/features.js file (you can copy the sample) containing the features that you want polyfilled. You can take a look at's docs for the available options.
  3. Create a src/headers.js file (you can copy the sample) containing the desired headers to be served alongside the JavaScript.

Now you can run yarn start to start a local server at http://localhost:8080. Visit that location in different browsers to view the polyfill. Note that since this server is running in development, it returns unminified JavaScript.


First, copy serverless-env.yml.sample to serverless-env.yml and fill in the relevant information. Below are the explanation for the options:

  • - any name unique to S3. Nothing actually gets stored in here, it's just used as the origin for CloudFront
  • distribution.alias - the domain that will be used for the CloudFront distribution (presumably something like
  • distribution.cert-arn - the ARN of an AWS Certificate Manager certificate that matches the alias (as in, as certificate for

With the config in place, install serverless by running npm install -g serverless. You can then run sls deploy --aws-profile [PROFILE] to deploy the lambda function, S3 bucket, and CloudFront distribution.

Once everything has been deployed, you can associate the CloudFront distribution with your domain through AWS Route53 by creating an alias record for the appropriate hosted zone. Then you can include script tag like the below to conditionally load only the correct polyfills:

<script type="text/javascript" src=""></script>


Bug reports and pull requests are welcome on GitHub at


The code is available as open source under the terms of the MIT License.


Generates polyfills based on user agent strings





No packages published

Contributors 4