Why Bother with HTML Script Type Attribute if Server Sets MIME Type? Despite the server assigning MIME types, HTML provides a type attribute for and <link> elements. While this attribute may seem superfluous, it can serve practical purposes and has historical significance.</p> <p>Doug Crockford explains that <script type="text/javascript"> is redundant since JavaScript is the default programming language in browsers. In XHTML, this attribute is mandatory but unnecessary, while in HTML it's advisable to omit it.</p> <p>However, the W3C opted for a more versatile type attribute that allows for MIME types. Unfortunately, no standard MIME type for JavaScript exists, leading to variations such as "text/javascript" and "application/ecmascript".</p> <p>Fortunately, all browsers default to JavaScript as the programming language, making it best practice to use <script> without the type attribute for optimal compatibility and brevity.</p> <p>To illustrate, five scripts were tested:</p> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre><script type="application/ecmascript">alert("1"); alert("2"); alert("3"); alert("4"); alert("5");Copy after login On Chrome, all scripts except for type="baloney" worked, while IE8 rejected type="application/ecmascript" and type="baloney". This suggests that while the type attribute can be safely disregarded, using an invalid value may lead to compatibility issues.