Pinafore-Web-Client-Frontend/src/routes/_utils/polyfills/loadPolyfills.js

34 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-01-28 01:31:26 +01:00
import {
2022-11-25 00:24:29 +01:00
importDynamicViewportUnitsPolyfill,
importIntlListFormat,
importIntlLocale, importIntlPluralRules, importIntlRelativeTimeFormat,
importRequestIdleCallback
} from './asyncPolyfills.js'
import { mark, stop } from '../marks.js'
2018-01-28 01:31:26 +01:00
async function loadIntlPolyfillsIfNecessary () {
// Have to chain these so that they load in the proper order.
// Luckily these requests aren't done in serial, because we're using the same Webpack
// chunk name for each one.
if (typeof Intl.Locale !== 'function') {
await importIntlLocale()
}
if (typeof Intl.PluralRules !== 'function') {
await importIntlPluralRules()
}
await Promise.all([
typeof Intl.RelativeTimeFormat !== 'function' && importIntlRelativeTimeFormat(),
typeof Intl.ListFormat !== 'function' && importIntlListFormat()
])
}
2021-06-19 18:29:32 +02:00
export async function loadPolyfills () {
mark('loadPolyfills')
await Promise.all([
typeof requestIdleCallback !== 'function' && importRequestIdleCallback(),
2022-11-25 00:24:29 +01:00
loadIntlPolyfillsIfNecessary(),
!CSS.supports('height: 1dvh') && importDynamicViewportUnitsPolyfill()
2018-01-28 01:31:26 +01:00
])
2021-06-19 18:29:32 +02:00
stop('loadPolyfills')
2018-02-09 07:29:29 +01:00
}