views:

552

answers:

2

What is the correct way to include the JQuery libraries via a master page? It appears there is a set for development and a set for production. I tried an "#if DEBUG" in my master page and it tripped errors left and right. I was also using <% %> style code and found out that I am not allowed to do that either. And my google-fu has not been good lately.

TIA

+2  A: 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"&gt;&lt;/script&gt;

Will include jQuery off Google's servers. The production one is the minified version (smaller file size).

Including this one will benefit you- There is a good chance (with more developers adopting this technique) that the person will have already visited a site with this link, and therefore having jQuery cached).

alex
How do I mark both of these as the answer? :)
Keith Barrows
You can't, unfortunately. Best you can do is vote them both up, and pick the one which helped you most as the accepted answer.
alex
+1  A: 

Scott Gu's Blog had a post on this a while back.

But essentially all you need on the master page is a link (as Alex posted earlier)

You can use code blocks to include a Intellisense version by doing :

<% if ( false ){ %>
     <script type="text/javascript" src="jquery-vsdoc.js"></script>
<% } %>

on any of the individual pages which you require intellisense on.

Ash
When doing anything with code nuggets in the site.master I get: {"The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)."}. While I did ask about JQuery I also have other JS files to include. What I *wanted* to do was:<% #if DEBUG { %> <script src="<%= Url.Content("~/Scripts/Debug/MicrosoftAjax.debug.js") %>" type="text/javascript"></script><% } else { %> <script src="<%= Url.Content("~/Scripts/MicrosoftAjax.js") %>" type="text/javascript"></script><% } %>Of course, none of this works in the site.master.
Keith Barrows
Actually - this works (per Phil Haack's blog entry http://haacked.com/archive/2009/01/27/controls-collection-cannot-be-modified-issue-with-asp.net-mvc-rc1.aspx)<br/><asp:PlaceHolder runat="server" id="mainScripts"><% #if DEBUG %><script src="<%= Url.Content("~/Scripts/Debug/MicrosoftAjax.debug.js") %>" type="text/javascript"></script><% #else %><script src="<%= Url.Content("~/Scripts/MicrosoftAjax.js") %>" type="text/javascript"></script><% #endif %></asp:PlaceHolder>
Keith Barrows