DEV Community

Cover image for Cross-Browser Support with React Polyfills - For IE & Smart TV Browsers
Neha Kadam
Neha Kadam

Posted on

1 1

Cross-Browser Support with React Polyfills - For IE & Smart TV Browsers

The biggest issue we all front-end developers have to deal with is supporting IE 😱. Another browser where App was not working well was Smart TV browsers. In case of React App, the blank page was rendered on both IE and Smart TV browsers.

After a lot of search and trial and errors, we found a partial solution in the React Documentation itself - Javascript Environment Requirements.

Solution

Since ES6 is not supported on Internet Explorer and older versions of Smart TV browsers, we have to use polyfills for the ES6 features. core-js is a standard library for polyfills. We can import polyfills only for the required features.
React also depends on requestAnimationFrame for which we can use raf polyfill.

Installing Dependencies

npm install core-js --save
npm install raf --save
npm install react-app-polyfill --save
Enter fullscreen mode Exit fullscreen mode

Adding a file to import polyfills - polyfills.js

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
import "core-js/es/symbol";
import "core-js/es/object";
import "core-js/es/function";
import "core-js/es/parse-int";
import "core-js/es/parse-float";
import "core-js/es/number";
import "core-js/es/math";
import "core-js/es/string";
import "core-js/es/date";
import "core-js/es/array";
import "core-js/es/regexp";
import "core-js/es/map";
import "core-js/es/weak-map";
import "core-js/es/set";
import "raf/polyfill";
Enter fullscreen mode Exit fullscreen mode

Adding following code in the root file - index.js

import "react-app-polyfill/ie9";
import "react-app-polyfill/ie11";
import "react-app-polyfill/stable";

if (window.fetch) {
  // Check whether ES6 is supported in Modern Browsers
  import("./app").then(function (module) {
    module.default();
  });
} else {
  // For legacy or old browsers
  import("./polyfills").then(() => {
    import("./app").then(function (module) {
      module.default();
    });
  });
}
Enter fullscreen mode Exit fullscreen mode

Build and Serve using Static Server

Even if you are using polyfills the app will not directly run on IE. You will have to build it and serve it using static server like serve.

IT WORKS!

AWS Q Developer image

Your AI Code Assistant

Implement features, document your code, or refactor your projects.
Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️