HTML5 [removed] declarations

后端 未结 3 469
滥情空心
滥情空心 2020-12-06 09:55

Is it still necessary (or even good practice) when using HTML5 to declare the script type when using a script block?

e.g.

相关标签:
3条回答
  • 2020-12-06 10:29

    The current draft of HTML5 doesn't require the type attribute for script tags.

    Also the <![CDATA is not required in HTML5 (it was XHTML specific anyway).

    0 讨论(0)
  • 2020-12-06 10:30

    Is it still necessary (or even good practice) when using HTML5 to declare the script type when using a script block?

    HTML 5 defines text/javascript as the default, and you'd be hard pressed to find a browser that didn't treat it as such. So you can omit it.

    Plus what about using a CDATA block in the script for browser parsing?

    Pointless unless you are writing XHTML 5 and using characters such as < or & in the script (but you should almost always be using external scripts anyway).

    0 讨论(0)
  • 2020-12-06 10:39

    The CDATA comments are for XML, so only applicable if you're serving your pages up as xml (which you shouldn't be if it's HTML5).

    As for the type attribute, it's optional now in HTML5.

    0 讨论(0)
提交回复
热议问题