Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript jQuery Basics (2014) Creating a Spoiler Revealer Preparation

Christopher Mlalazi
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Christopher Mlalazi
Front End Web Development Techdegree Graduate 17,305 Points

jQuery Link Codes: Workspace Vs jQuery Download

I notice that the jQuery link code in Workspace seems different to the one we were directed to in the jQuery website (CDN). The one in worskspace has 'type" plus 'charset' is I have copied and pasted it here:

<script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript" charset="utf-8"></script>.

But if you look at the one from 'jQuery's CDN provided by MaxCDN' it does not have the 'type' and 'charset' like here:

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>

So what is the difference and why are we being told to use CDN and Treehouse goes on to use something else in their examples without any warning or telling us why?

[MOD: added ```html formatting -cf]

5 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Looking at the MDN page on <script> element it's related to HTML 4 vs 5. HTML 5 may not be in use everywhere, yet, so the HTML 4 syntax is safer.

<!-- HTML4 and (x)HTML -->
<script type="text/javascript" src="javascript.js"></script>

<!-- HTML5 -->
<script src="javascript.js"></script>

The use of the charset is to stipulate the encode for the external (in this case the jquery.js) file. This, again, is a safety usage for cases where the main HTML page is using a different encoding than the "utf-8" contained in the jquery.js file.

Kingsley Felix
Kingsley Felix
8,591 Points

i guess we can use the HTML5 version now?

Matthias J.
Matthias J.
20,355 Points

i would recommend the teamtreehouse version. its "safer" because you tell the browser how to interpret the src-file. this would be important if you use a different charset for your code than the .js file is :)

Matthias J.
Matthias J.
20,355 Points

because most of the time it works fine without adding the attributes you mentioned. we are all a bit lazy :P i have to admit it, i also use the shorter version ;(

Christopher Mlalazi
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Christopher Mlalazi
Front End Web Development Techdegree Graduate 17,305 Points

Thanks Mathias, am actually using the teamtreehouse code it works perfectly but I was curious why it's different to the one that was pointed it in her jQuery website downloads