logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

load_polyfills.js (1272B)


  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. Object.values &&
  15. Number.isNaN &&
  16. window.Symbol &&
  17. Array.prototype.includes
  18. );
  19. // Latest version of Firefox and Safari do not have IntersectionObserver.
  20. // Edge does not have requestIdleCallback and object-fit CSS property.
  21. // This avoids shipping them all the polyfills.
  22. const needsExtraPolyfills = !(
  23. window.IntersectionObserver &&
  24. window.IntersectionObserverEntry &&
  25. 'isIntersecting' in IntersectionObserverEntry.prototype &&
  26. window.requestIdleCallback &&
  27. 'object-fit' in (new Image()).style
  28. );
  29. return Promise.all([
  30. needsBasePolyfills && importBasePolyfills(),
  31. needsExtraPolyfills && importExtraPolyfills(),
  32. ]);
  33. }
  34. export default loadPolyfills;