JavaScript 内容类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3699873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaScript content-type
提问by Svish
When I add JavaScript files to web pages, I have always done for example like this:
当我将 JavaScript 文件添加到网页时,我总是这样做,例如:
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript">
// Custom script
</script>
But today I discovered in the response headers that JavaScript are actually served as application/javascript. Why is that? Is both correct? Or should I change one to the other? What's going on here?
但是今天我在响应头中发现 JavaScript 实际上是作为application/javascript. 这是为什么?两者都正确吗?或者我应该把一个换成另一个?这里发生了什么?
回答by bluesmoon
with HTML5, you can just omit the type attribute completely. All browsers assume a default type of JavaScript.
使用 HTML5,您可以完全省略 type 属性。所有浏览器都假定默认类型的 JavaScript。

