Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 412
  • Last Modified:

CDATA

Can someone kindly explain what this code block is doing?  Inherited code and I am not familiar with CData.

  <script type='text/javascript'>
    //<![CDATA[
      !window.jQuery && document.write(unescape('%3Cscript src="../js/libs/jquery-1.7.1.min.js"%3E%3C/script%3E'));    // scripts concatenated and minified via ant build script
    //]]>
  </script>

Open in new window

0
kkbenj
Asked:
kkbenj
  • 2
  • 2
2 Solutions
 
StingRaYCommented:
This script includes jQuery framework if it is not included.
CDATA block is a character data block, usually used in XHTML.
If you are writing a plain HTML, you can remove "//<![CDATA[" and "//]]>".
0
 
Robert SchuttSoftware EngineerCommented:
The CDATA part is commented out but could be necessary to maintain valid xml/xsl at some other point.

The javascript code checks if jQuery is available and if not, insert the script tag to include it into the html.
0
 
kkbenjAuthor Commented:
Nothing in XHtml.  Thank you for the information.

One more related question: is that block of code even necessary since:
      <script src='../js/libs/jquery-1.7.1.min.js'></script>
is included in the header?
0
 
StingRaYCommented:
No, it is not necessary anymore.
0
 
kkbenjAuthor Commented:
Thank you both!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now