In HTML5, you no longer need to include the type in a script tag when you are using JavaScript.
Are any common browsers (IE6+, Firefox 2+, Safari 3+, Opera 9+ or similar) going to break if the type is removed from all the <script>
tags?
So, is changing the following:
<script type="text/javascript" src="/path/js.js"></script>
<script type="text/javascript">
...
</script>
to:
<script src="/path/js.js"></script>
<script>
...
</script>
... going to break anywhere?
The type attribute in JavaScript is optional since the introduction of HTML5 brought some new improvements. JavaScript became the default language for HTML5 and modern browsers. So, now adding text/javascript isn't required in <script> tag.
Complete HTML/CSS Course 2022 You can place the <script> tags, containing your JavaScript, anywhere within your web page, but it is normally recommended that you should keep it within the <head> tags. The <script> tag alerts the browser program to start interpreting all the text between these tags as a script.
Definition and Usage. The <script> tag is used to embed a client-side script (JavaScript). The <script> element either contains scripting statements, or it points to an external script file through the src attribute. Common uses for JavaScript are image manipulation, form validation, and dynamic changes of content.
<script> tag must not be included in a <header> Google Tag Manager Tag should be placed immediately after the opening <body> tag and not inside any other HTML element.
No it won't break any of the popular browsers, including the ones you mention. The <script>
tag will work fine without the type
attribute, because all popular browsers will default to JavaScript.
Quoting Douglas Crockford:
type="text/javascript"
This attribute is optional. Since Netscape 2, the default programming language in all browsers has been JavaScript. In XHTML, this attribute is required and unnecessary. In HTML, it is better to leave it out. The browser knows what to do.
going to break anywhere?
No
As per HTML4 specification, it won't be a valid markup only as per W3C Validator if you remove type
attribute from the <script>
tag although your script should still work fine across browsers.
If you are asking in HTML5 perspective, there is no problem in leaving that out.
The type attribute was useful a long time ago, when JavaScript was not standardized, along with differences between different versions of the same browser. You could use other languages like vbscript, but in the real world nobody has used it in years.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With