闭社主体 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.

36 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.
  20. // This avoids shipping them all the polyfills.
  21. const needsExtraPolyfills = !(
  22. window.IntersectionObserver &&
  23. window.requestIdleCallback
  24. );
  25. return Promise.all([
  26. needsBasePolyfills && importBasePolyfills(),
  27. needsExtraPolyfills && importExtraPolyfills(),
  28. ]);
  29. }
  30. export default loadPolyfills;