最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

apache2 - JavaScript content-type - Stack Overflow

programmeradmin1浏览0评论

When I add JavaScript files to web pages, I have always done for example like this:

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

When I add JavaScript files to web pages, I have always done for example like this:

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

Share Improve this question asked Sep 13, 2010 at 11:14 SvishSvish 158k182 gold badges476 silver badges631 bronze badges 7
  • I think that this one explains it good: annevankesteren.nl/2006/05/javascript-mime-type – Tomasz Kowalczyk Commented Sep 13, 2010 at 11:16
  • 2 Also see Why write <script type=“text/javascript”> when the mime type is set by the server? – Marcel Korpel Commented Sep 13, 2010 at 11:52
  • Well, it explained that application/javascript was the one I should use. But not which one I should use... Also its from 2006. So is it still the case that I should use text/javascript because of browsers, or? – Svish Commented Sep 13, 2010 at 11:54
  • @Svish: At least IE 7 (and 8?) does have problems with script elements with MIME-type set to application/javascript, and as there are still plenty IE users out there… – Marcel Korpel Commented Sep 13, 2010 at 12:39
  • Well, link appears to be broken. Good answer should link to original sources, but also refer most important contents briefly - just because this happens all the time. – Olli Commented Aug 29, 2012 at 8:15
 |  Show 2 more ments

1 Answer 1

Reset to default 2

with HTML5, you can just omit the type attribute pletely. All browsers assume a default type of JavaScript.

发布评论

评论列表(0)

  1. 暂无评论