Zoltan King
Zoltan King

Reputation: 2292

What is the best way to load Babel?

I have a first generation iPad mini. It's a about 8 years old and although it displays my page correctly some functionalities that require JavaScript doesn't seem to work. If I understood correctly I need to load Babel or something like that. Is that true? But what's the best way to load Babel? should I just use a script tag like so:

<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>

Is that enough?

Upvotes: 1

Views: 228

Answers (1)

aross
aross

Reputation: 3606

TL;DR: don't load Babel in the browser in a production env

It depends on what exactly doesn't work. If it's simply syntax and some ES6 classes/functions, that's probably solved by Babel which transforms syntax and has some polyfills. You can transpile your JS server-side if you're concerned about load times (which makes sense for older devices). If you can't do it on the server, you can just deploy a JS file you transpiled on your workstation. Also, if you go here and click on "In the browser", you'll see this:

Compiling in the browser has a fairly limited use case, so if you are working on a production site you should be precompiling your scripts server-side.

You should probably also have a look at CanIUse. Then you can decide how much time you want to invest in the first place. const for example is supported by 99.8% of users globally.

However, it can be that your page uses JS to do some complex interaction that depends on pointers, touch events and such. In that case you probably need to rewrite a lot of it. This does not apply to your situation, but generally may impact someone's decision on what browsers to support.

Upvotes: 2

Related Questions