I was reading a book about learning JavaScript, and there was these paragraphs:
...in middle of 1997, Microsoft and Netscape, with associate of
European Computer Manufactures Association,
released the first
version of a standard that named ECMAScript
or with official form
ECMA-262
...
As much as I was found in this book and something like this, JavaScript and ECMAScript are the same and are different just in name.
From other hand, in Dreamweaver, bracket, and some other editors, there's some autocomplete suggestion like this:
when I want to add a script tag to my page.
I want to know if there are differences between ECMAScript
and Javascript
and when should I use text/javascript
or text/ecmascript
?
ECMAScript is a language specification standardized by ECMA International as ECMA-262 and ISO/IEC 16262. JavaScript is a programming language that implements this specification. ECMAScript exists in several editions. The latest edition is the 6th (in 2016), but most JavaScript implementations are only 5th edition compliant so far.
Besides ECMAScript common JavaScript implementations usually add more functionality, which might be standardized by other institutions (like the W3C) or might be proprietary (aka "browser-specific") features of the specific implementation. So you could say, that ECMAScript represents a subset of JavaScript.
However, the MIME types for JavaScript code are defined in the RFC 4329 document, which states that text/javascript
and text/ecmascript
are both obsolete and should be replaced by application/javascript
and application/ecmascript
:
Use of the "text" top-level type for this kind of content is known to
be problematic. This document thus defines text/javascript and text/
ecmascript but marks them as "obsolete".
The RFC defines stricter processing rules for the application/ecmascript
than for application/javascript
, but this refers to the handling of MIME-type parameters and the character encoding and not to the interpretation of the code itself:
In the cited case, implementations of the types text/javascript, text/ecmascript, and application/javascript SHOULD and implementations of the type application/ecmascript MUST implement the requirements defined in this section: [...]
For the application/ecmascript media type, implementations MUST NOT process content labeled with a "version" parameter as if no such parameter had been specified; [...]
The following error processing behavior is RECOMMENDED for the media types text/javascript, text/ecmascript, and application/javascript, and REQUIRED for the media type application/ecmascript.
In general I would use application/javascript
(or text/javascript
if you have to support older browsers like IE8) to prevent cross-browser issues. If you only care about HTML5, you can also omit the type-attribute completely.