1
<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 ?

2 Answers 2

1

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).

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.