Using custom type attribute in <script> tags such as jQuery's text/x-jquery-tmpl

…衆ロ難τιáo~ 提交于 2019-11-29 02:32:35

问题


I noticed that jquery's beta template plugin is using, the type attribute "text/x-jquery-tmpl"

e.g

<script type="text/x-jquery-tmpl">

I've not seen custom use of the type attribute in the past. Has anyone seen current examples of this in use or perhaps ways mere mortal developers such as I can use this in our own code?

I presume that it's sort of a MIME type, however I would of thought that MIME type support was up to the browser. So I would of assumed that custom MIME types would be unsupported?


回答1:


The type actually does indicate what sort of script is there. If the browser doesn't understand it, it should ignore it. In this case, it's a convenient and semantic sort of way to include the source of the template without displaying it on the screen.

Usually with jquery template, you'll give it an id and refer to it that way with your $(id).tmpl call.

script def here: http://www.w3.org/TR/html401/interact/scripts.html#idx-scripting_language

examples of tmpl here: http://api.jquery.com/tmpl/




回答2:


No, MIME are provided by the server to identify resources. The browser then acts on the types it recognizes.

Yes, in the HTTP connection the browser lists the types it can recognize so the server can choose types that fit better (an example here would be HTML 5 and video, where you have some codec options and the browser may support only a subset).

In this case, the specific MIME helps to signal the browser a warning: "This is not normal Javascript, don't act on it like if it was."



来源:https://stackoverflow.com/questions/6452142/using-custom-type-attribute-in-script-tags-such-as-jquerys-text-x-jquery-tmpl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!