Reputation: 4435
<script type="media_type"></script>
As far i know the valid script type could be javascript or ecmascript or some other valid value. But in react they use text/babel
As we know babel is nothing but a transpiler. Which task is to convert code into plain javascript
<script type="text/babel">
</script>
Why and How browser response this attribute value if it is a transpiler ?
Upvotes: 1
Views: 143
Reputation: 191986
If you use something like babel-standalone to transpile JS code on the fly in the browser, you don't won't the browser to try and run the script before it's transpiled, so type="text/javascript"
should not be used.
On the hand, the standalone transpiler should no what code blocks to transpile, and it uses type="text/babel"
to do so.
Upvotes: 1
Reputation: 943591
React doesn't say the script is written in JavaScript because it isn't written in JavaScript.
If the browser doesn't recognise the script type, then it does nothing with it beyond inserting it into the page as a text node.
The page, presumably, has some JavaScript which will extract that text from the DOM and do something with it (and that JS will use the type to identify which script elements to read text from).
Upvotes: 1