google / model-viewer

Easily display interactive 3D models on the web and in AR!
https://modelviewer.dev
Apache License 2.0
6.89k stars 815 forks source link

Remove IE11-specific code #4603

Closed Frank3K closed 9 months ago

Frank3K commented 9 months ago

Description

While browsing through the code, I found some IE11-specific code. Since IE11 is not a supported browser anymore (by model-viewer's README), nor by three.js, I think this code can be refactored to more modern code. This change leads to a somewhat smaller bundle size.

Bundle size

File size after a npm run build:

File name Old size (byte) New size (byte) Size diff (byte) Size difference (%)
model-viewer-module-umd.js 811477 810695 -782 -0,10
model-viewer-module-umd.js.map 1824995 1822288 -2707 -0,15
model-viewer-module-umd.min.js 375008 374852 -156 -0,04
model-viewer-module-umd.min.js.map 1296291 1295330 -961 -0,07
model-viewer-module.js 849033 847786 -1247 -0,15
model-viewer-module.js.map 1833299 1830557 -2742 -0,15
model-viewer-module.min.js 396451 396295 -156 -0,04
model-viewer-module.min.js.map 1330861 1329425 -1436 -0,11
model-viewer-umd.js 1751653 1750943 -710 -0,04
model-viewer-umd.js.map 4288624 4285917 -2707 -0,06
model-viewer-umd.min.js 896545 896389 -156 -0,02
model-viewer-umd.min.js.map 2956094 2955163 -931 -0,03
model-viewer.d.ts 82362 82362 0 0,00
model-viewer.js 1818886 1817639 -1247 -0,07
model-viewer.js.map 4300191 4297449 -2742 -0,06
model-viewer.min.js 920632 920476 -156 -0,02
model-viewer.min.js.map 2986699 2985245 -1454 -0,05

Testing

npm run test succeeds on my local machine.

UMD bundles

In the rollup config I found this code:

https://github.com/google/model-viewer/blob/99fa9a8ba5c31ba161880f8b82248a196759dee4/packages/model-viewer/rollup.config.js#L73-L83

If I understand correctly this is not just for IE11, but for any browser that does not support ES Modules. The specific lines were introduced in https://github.com/google/model-viewer/commit/92111b3ac68c22508bc00edb6300404407308008. Since all modern / supported browsers support ES6 Modules (caniuse), I doubt if the UMD bundles are still required. I do not see any usage of the umd bundles in the repository itself (e.g. in the aforementioned unit test build).

Because I am not sure, I did not touch the rollup config.