Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove polyfills for IE #2506

Closed
5 tasks done
Tracked by #2621
vanitabarrett opened this issue Jan 19, 2022 · 4 comments
Closed
5 tasks done
Tracked by #2621

Remove polyfills for IE #2506

vanitabarrett opened this issue Jan 19, 2022 · 4 comments
Labels
documentation User requests new documentation or improvements to existing documentation javascript performance
Milestone

Comments

@vanitabarrett
Copy link
Contributor

vanitabarrett commented Jan 19, 2022

What

At the moment, we ship polyfills to all browsers even when they're not needed. We think around 50% of the JavaScript we ship is polyfills (this might say more about the amount of JavaScript we have, rather than the size of the polyfills).

Having to include polyfills also means we tend to restrict ourselves to features that we know are either 1) well supported, or 2) don't require large polyfills to work in older browsers.

Why

There is a performance impact if we're shipping unnecessary JavaScript to browsers that don't need it.
Our current approach puts some restrictions on the JavaScript features we use. This isn't necessarily causing problems right now, but might do in future when we come to build more complex components. (also depends on #2503 )

Who needs to work on this

Developers

Who needs to review this

Developers

Done when

Depends on our browser support proposal being approved by the community. If we go down the route of dropping IE support to 'functional':

@NickColley
Copy link
Contributor

NickColley commented Aug 17, 2022

On a project I removed the polyfills in the build step, sharing here if anyone is Googling finds this issue and wants to do the same:

Before After
9.9kb gzipped (39.2kb expanded) 6.1kb gzipped (25.4kb expanded)

Rollup Plugin:

// file: rollup-remove-polyfills.js
// Based on https://github.com/proteriax/rollup-plugin-ignore

// Replace polyfills with empty files that'll get removed with tree shaking.
function removePolyfills() {
  const emptyFile = "export default {}";
  const emptyFileName = "\0rollup_plugin_ignore_empty_module_placeholder";
  return {
    resolveId(importee) {
      return importee.includes("vendor/polyfills") ? emptyFileName : null;
    },
    load(id) {
      return id === emptyFileName ? emptyFile : null;
    },
  };
}

module.exports = removePolyfills;
// file: index.mjs
import { initAll } from "govuk-frontend/govuk-esm/all.mjs";

initAll();
rollup ./index.mjs --file output.js --plugin ./rollup-remove-polyfills.js 

@36degrees
Copy link
Contributor

Is there something else to review after #3570 or should this go back to in progress / backlog?

@domoscargin domoscargin self-assigned this May 23, 2023
@domoscargin domoscargin removed their assignment Jun 5, 2023
@domoscargin domoscargin added the documentation User requests new documentation or improvements to existing documentation label Jun 5, 2023
@domoscargin
Copy link
Contributor

Paging @claireashworth, since the last bit of work on this is documentation.

Though we first have to decide what polyfilling actually looks like going forward.

@36degrees
Copy link
Contributor

This is done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation User requests new documentation or improvements to existing documentation javascript performance
Projects
Development

No branches or pull requests

6 participants