Fetching scripts with an invalid type/language attributes is deprecated and will be removed

只愿长相守 提交于 2019-12-22 08:30:22

问题


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.


回答1:


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>




回答2:


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.




回答3:


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>



回答4:


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.



来源:https://stackoverflow.com/questions/41208177/fetching-scripts-with-an-invalid-type-language-attributes-is-deprecated-and-will

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!