5 ms·
More devs should know about Intl - it's a great resource for a HUGE number of tasks as well as being a great way to smooth localization. I only became fully awa
by johnzim 5y ago
More devs should know about Intl - it's a great resource for a HUGE number of tasks as well as being a great way to smooth localization. I only became fully aware of it in the last 12 months, so I'd wager there's a lot of other devs who've missed out.
One helping hand is that libraries like date-fns (http://date-fns.org http://date-fns.org) use it liberally under the hood.
- colonelpopcorn 5y agoI know about it, but I can't use it because it isn't supported in Internet Explorer 11: https://caniuse.com/?search=Intl https://caniuse.com/?search=Intl Hopefully, more people will follow suit and ban IE11 when O365 no longer supports it: https://docs.microsoft.com/en-us/lifecycle/announcements/internet-explorer-11-support-end-dates https://docs.microsoft.com/en-us/lifecycle/announcements/int...
- heinrich5991 5y agoMost stuff can be polyfilled. Is this not one of these?
- fiddlerwoaroof 5y agoThe locale data for the polyfills can add a lot to bundle size.
- afavour 5y agoWell, you either need to format dates or you don't. The idea that you won't use Intl because the IE11 polyfill adds to much to your bundle size is a bit of a head scratcher.
- fiddlerwoaroof 5y agoThe issue is whether it’s worth spending that bundle size on an obsolete browser. If not, it could be reasonable to do some naive formatting on IE11 and show a message mentioning that the browser is unsupported and things may render incorrectly.
- Dylan16807 5y agoYour IE11 polyfills don't have to be in the same bundle as everything else.
- skrebbel 5y agohttps://cdn.polyfill.io/v3/url-builder/ https://cdn.polyfill.io/v3/url-builder/ is pretty great for this, it'll detect the browser user agent and send down the right polyfill. Ie on modern browsers it'll send down an empty response.
- capableweb 5y agoWell, great sometimes. Not great if you don't trust a random 3rd party to host essential client-side code for you or if you don't feel like running yet another, maybe unsupported in the future, service for the next X years.
- Svenskunganka 5y agoYou can always self-host it: https://github.com/financial-times/polyfill-service https://github.com/financial-times/polyfill-service
- skrebbel 5y agoTrue. We have an "if IE then emit polyfill.io <script> tag" call in the backend, which limits the security surface area to IE and also prevents an otherwise unnecessary extra HTTP request (we only use it for Intl). We feel that's a reasonable middle ground. If I'd use it for all polyfills (which we should maybe consider!), we'd likely self-host the service.
- zbraniecki 5y agoI'm one of the leaders of the ICU4X project which is a Rust implementation of ECMA-402 aiming to back client-side solutions. We hope to eventually back SpiderMonkey (Firefox JS engine) implementation with it, but we also want to target WASM and in result expose it as a polyfill for any browser to use. I don't know if by the time ICU4X is 1.0 IE11 will still matter, but it may be possible to compile it to asm.js and run in IE11 maybe?
- stephenhuey 5y agoJust stumbled upon it a few weeks ago and just in time for handling some stuff in my current project!
- baumandm 5y agodate-fns actually barely uses Intl. Rather, it has custom locale files that must be imported to use: https://date-fns.org/v2.22.1/docs/I18n https://date-fns.org/v2.22.1/docs/I18n. There is a single intlFormat function: https://date-fns.org/v2.22.1/docs/intlFormat https://date-fns.org/v2.22.1/docs/intlFormat Once I realized this I switched to Luxon, which is entirely Intl based: https://moment.github.io/luxon/docs/manual/intl.html https://moment.github.io/luxon/docs/manual/intl.html