Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference b/w <script

Tags:

javascript

What is the difference between:

  1. < script language="javascript" type="text/javascript">< /script>

  2. < script type="text/javascript">< /script>

  3. < script language="javascript">< /script>

like image 394
Karandeep Singh Avatar asked Jun 03 '10 05:06

Karandeep Singh


People also ask

Why is it called a script?

A script is a written version of a play or movie. If you're auditioning for a movie, you'll get the script to practice a scene or two. Script comes from the Latin scrībĕre, meaning "to write," and all its meanings have to do with something written. Your handwriting is your script.

What is difference between program and script coursera?

Programming languages are a way for coders to communicate with computers using compiled languages—source code compiled to convert into machine code. Scripting languages are a type of programming language. They are interpreted rather than requiring compilation.

What is the difference between a scripted and compiled language?

'Compiled' means that a programming language has its own compiler that translates the syntax into machine code before runtime. In contrast, scripting languages are interpreted line by line during runtime by the interpreter of the platform they are running on.


2 Answers

All of them are technically deprecated, but the second annoys people least. :)

Both language (see W3C XHTML 1.1) and text/javascript are deprecated (see MIME registry for text). The recommended mime type is application/javascript, but this is not backwards-compatible.

like image 197
Matthew Flaschen Avatar answered Sep 25 '22 02:09

Matthew Flaschen


Number 2 is the best you can do for now and for the foreseeable future.

First, the language attribute is deprecated in the HTML 4.01 specification and the draft HTML 5 specification, and omitted from XHTML 1.0 Strict, so options 1 and 3 are out.

Second, do you need a type attribute at all? Yes. HTML 4.01 and XHTML 1.0 specifies the type attribute as required while HTML5 has it as optional, defaulting to text/javascript. Therefore until HTML5 is finalised and widely implemented, you must have the type attribute if you want your HTML to be valid, which rules out the simple <script></script> (I know this wasn't one of the original options, but it's something that I have seen recommended).

Thirdly, what should go in the type attribute? As noted by Matthew Flaschen, the MIME type application/javascript registered in 2006 is intended to replace text/javascript. A quote from the relevant RFC:

This document thus defines text/javascript and text/ecmascript but marks them as "obsolete". Use of experimental and unregistered media types, as listed in part above, is discouraged. The media types,

  * application/javascript
  * application/ecmascript

which are also defined in this document, are intended for common use and should be used instead.

However, IE (up to and including version 8) doesn't execute script inside a <script> element with a type attribute of either application/javascript or application/ecmascript, so these are both unusable for the foreseeable future and we're stuck with text/javascript.

like image 26
Tim Down Avatar answered Sep 25 '22 02:09

Tim Down