4

I read in "jQuery for ASP.NET Developers" this re: getting Intellisense support in VS for jQuery: "....a VSDoc file for jQuery...The VSDoc file...uses the same name as your JavaScript file with -vsdoc inserted before the .js file extension. For example, if my jQuery file is called jQuery-1.3.2.js, then the vsdoc file would be called jQuery-1.3.2-vsdocjs. the VSDoc file must exist in the same directory as your jQuery file so that VS can find it."

Does this mean that using a CDN for jQuery files prevents Intellisense from working?

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862

1 Answers1

5

You can use a CDN and still have Intellisense support in Visual Studio. There are two ways to do this:

  1. Add an Intellisense reference to the *vsdoc.js file that is hosted on the CDN. Go to Tools | Options:

    Options dialog

    Note that you will need to make an entry for each *vsdoc.js that you want to use.

  2. If you know that the *vsdoc.js file is co-located in the same directory with the js file on the CDN (like it is on the ASP.NET CDN), AND you're using MVC, you can just update your _references.js file to reflect this:

/// <reference path="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.0.js" />

If you need help with _references.js, see my blog entry here.

Be sure to update your webpage (or _Layout.cshtml) reference to actually use the CDN too. Note that the js path that you use for your web pages doesn't have to be the same as your Intellisense reference (of course, you obviously want them to be the same version)!

<!DOCTYPE html>

<html>
<head>
    <title>@ViewBag.Title</title>
</head>
<body>
    <div id="body">
        @RenderBody()
    </div>
    <script src="@Url.Content("http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.js")" type="text/javascript"></script>
    @RenderSection("scripts")
</body>
</html>

NOTE: The examples above assume that you're not using ASP.NET 4.5 bundling, or taking advantage of CDN features such as path mirroring and reverse proxies. I assume that if you're using these features, you know what needs to be done to get them running.

newmanth
  • 408
  • 7
  • 18
  • Since I've never of ASP.NET 4.5 bundling, path mirroring or reverse proxies, I'm probably safe that way (ignorance is bliss, they say). However (alas!), I have no JavaScript entry in my Tools | Options tree. – B. Clay Shannon-B. Crow Raven Jun 20 '13 at 20:26
  • What version of VS are you running? – newmanth Jun 20 '13 at 20:40
  • My example is from 2012, but I think the menu options are still the same. I just looked at my screen snap and realized the path is not clear. In the Options dialog, drill down to Text Editor | JavaScript | Intellisense | References. You should find it there. – newmanth Jun 21 '13 at 14:58
  • No, I have a Text Editor | JScript, but no JavaScript, and no Intellisense below JScript. – B. Clay Shannon-B. Crow Raven Jun 21 '13 at 15:05
  • Argh, it appears VS 2010 does JavaScript Intellisense differently than 2012. Unfortunately, since I don't have that version installed, I'm afraid that I will be of little help to you. – newmanth Jun 24 '13 at 18:00