闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.1 KiB

  1. // Convenience function to load polyfills and return a promise when it's done.
  2. // If there are no polyfills, then this is just Promise.resolve() which means
  3. // it will execute in the same tick of the event loop (i.e. near-instant).
  4. function importBasePolyfills() {
  5. return import(/* webpackChunkName: "base_polyfills" */ './base_polyfills');
  6. }
  7. function importExtraPolyfills() {
  8. return import(/* webpackChunkName: "extra_polyfills" */ './extra_polyfills');
  9. }
  10. function loadPolyfills() {
  11. const needsBasePolyfills = !(
  12. window.Intl &&
  13. Object.assign &&
  14. Number.isNaN &&
  15. window.Symbol &&
  16. Array.prototype.includes
  17. );
  18. // Latest version of Firefox and Safari do not have IntersectionObserver.
  19. // Edge does not have requestIdleCallback and object-fit CSS property.
  20. // This avoids shipping them all the polyfills.
  21. const needsExtraPolyfills = !(
  22. window.IntersectionObserver &&
  23. window.requestIdleCallback &&
  24. 'object-fit' in (new Image()).style
  25. );
  26. return Promise.all([
  27. needsBasePolyfills && importBasePolyfills(),
  28. needsExtraPolyfills && importExtraPolyfills(),
  29. ]);
  30. }
  31. export default loadPolyfills;