Difference between adding <![CDATA[ in page source v/s dynamically using javascript

190 views Asked by At

Is there a difference between --

<![CDATA[
// content of your Javascript goes here
]]>
  1. Adding it as part of html response from server v/s
  2. Adding it dynamically after page load using a javascript (lets say $('body').append(/CDATA_goes_here/))

Main question here is whether CDATA needs to be available as part of page source or not?

1

There are 1 answers

0
Quentin On

Leaving aside the general issues with adding content using JS, CDATA doesn't make any difference.

It renders in an XHTML document and gets parsed as a comment in an HTML document.