標籤:
type="application/javascript"html script 標籤中 type有如下這些值,請問分別是什麼意思,在什麼情況下使用?
- type="text/javascript"
- type="application/javascript"
- type="application/x-javascript"
這3個有什麼區別嗎 ?
The traditional MIME type forJavaScript programs is "text/javascript".Another type that has been used is "application/x-javascript"(the "x" prefix indicates that it is an experimental, nonstandard type). RFC 4329 standardized the "text/javascript" type because it is in common use.However, because JavaScript programs are not really text documents, it marks this type as obsolete and recommends "application/javascript"(without the "x-") instead.At the time of this writing,"application/javascript" is not well supported, however.That might be the reason why "application/x-javascript" is used by a lot of webpages.
大致意思是:傳統的javascript程式的MIME類型是“text/javascript”,其他使用的還有"application/x-javascript"(x首碼表示這是實驗性的,不是標準的類型),RFC4329規定了“text/javascript”類型,因為它普遍被使用。然而,javascript程式並不是真正的文字檔,這就表示這個類型已經意味著過時了,而推薦使用"application/javascript"(去除x首碼)。然而,在寫程式的時候,"application/javascript"沒有很好的支援。這也就是"application/x-javascript"不被使用在很多網頁中的原因。
您是否很疑惑為什麼我們沒有在<script>標籤中使用 type="text/javascript"?
在 HTML5 中,不必那樣做了。JavaScript 是 HTML5 以及所有現代瀏覽器中的預設指令碼語言!
type="application/javascript"