Fetching scripts with an invalid type/language att

2019-05-06 06:24发布

I start to learn react.js using JSX. To use it I connect a babel library (not matter what is a version) and write a JSX code in a JS file:

<script src="js/app.js" type="text/babel"></script>

type="text/babel" - necessarily.

But there is a warning in Chrome: "Fetching scripts with an invalid type/language attributes is deprecated and will be removed in M56, around January 2017. See https://www.chromestatus.com/features/5760718284521472 for more details."

But everything is OK, when I write a JSX code in DOM. Actually, the problem goes away without a "src=..." I want to write the code in JS file. What should I do for avoid a deprecation? Thank you.

4条回答
疯言疯语
2楼-- · 2019-05-06 06:33

The difference is that if you just do

<script type="text/babel">
// code here
</script>

you're not fetching the script from anywhere. But in your first example, you are.

If you're fetching the code from the server, you should transpile it server-side and then fetch the transpiled result, rather than fetching it and then transpiling on the client.

查看更多
Emotional °昔
3楼-- · 2019-05-06 06:34

If you can't transpile on the server then just put the code on the same page.

So instead of

<script type="text/babel" src="./app.js"></script>

try

<script type="text/babel"> //code from ./app.js goes here </script>

查看更多
Juvenile、少年°
4楼-- · 2019-05-06 06:36

This is not an issue for babel-standalone, which I presume is what you're using as "a babel library" in your browser. Comment from one of the babel-standalone devs on this issue:

This is not relevant to babel-standalone, as we don't rely on preloading. Babel-standalone is still working on Chrome 56. Closing this issue.

https://github.com/babel/babel-standalone/issues/72

If you're not using babel-standalone, then maybe give it a try. It lets you have ES6, React etc without needing a build step, so is a great way to get started and expermient. It's not really suitable for production apps though.

查看更多
趁早两清
5楼-- · 2019-05-06 06:51

I m new here, but try to use

<script data-src="javascript.js" type="text/javascipt" ></script>

instead of

<script src="javascript.js" type="text/javascipt" ></script>
查看更多
登录 后发表回答