6

History

I created a new ASP.NET MVC 4.0 project that was basic and didn't include jQuery or other scripts that the Intranet and Internet templates insert by default. I then went to add the scripts using NuGet and installed the latest version of all the jQuery and related files that are normally installed by the MVC Intranet and Internet templates.

When I tried running the application I started to receive errors. Apparently there are incompatibilities with the libraries/extensions that were written previous to jQuery 1.9. It seemed like after fixing an issue I'd run into another. I finally gave up and copied the versions of the js files that would have installed. This resolved the issues I was able to use features such as remote validation.

Questions

Since I'm new to ASP.MVC, I'd like to know what the Best Practice is related to jQuery updates. I assume I need to wait until all the libraries/extensions have caught up, but I would need to follow the status of each library/extension to determine when I could upgrade.

  1. Is it simply better to wait and just use the versions that are installed with the MVC templates and not upgrade? And when the next update for MVC comes out, then copy those libraries/extensions into the scripts folder that the updated templates use?
  2. I noticed that the MVC templates do not install the jQuery NuGet packages but install files to the Content and Script folders. Is this to prevent developers from upgrading and experiencing the issues I found with using newer version of the libraries/extensions?
  3. Does Microsoft time updates to jquery.unobtrusive-ajax.js and related libraries to updates to ASP.NET MVC? If so then it would seem to make sense to hold off updating dependencies until ASP.NET MVC is updated.
Cœur
  • 37,241
  • 25
  • 195
  • 267
Josh
  • 8,219
  • 13
  • 76
  • 123
  • 1
    I always like it when someone puts forth the effort to ask about best practices. – Charles Burns Feb 05 '13 at 21:39
  • First of all I would be using the CDN in production. Second you obviously have to test everything if you decide to upgrade. – The Muffin Man Feb 05 '13 at 22:01
  • @Nick, It would be the same issue of referencing the file locally or by CDN, assuming I'm referencing a specific version. Worse if I used a reference to the latest since that would have broken when the CDN updated file versions. Agree on testing, but I don't want to waste a ton of time if it turns out the Best Practice is to wait until the next MVC update. – Josh Feb 05 '13 at 22:13
  • @Josh When you link to a CDN file you don't link to an ambiguous name such as thecdn.com/jquery.js. You link to thecdn.com/jquery-1.8.2.js. In other words it doesn't change. If a new version comes out they add another one like thecdn.com/jquery-1.9.js. All the versions are here and existing ones won't change on you: https://developers.google.com/speed/libraries/devguide#jquery Whether you CDN or not, upgrading your jquery version will require testing. – The Muffin Man Feb 05 '13 at 22:42
  • @Nick, I was referring to references such as: http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js and http://code.jquery.com/jquery-latest.min.js – Josh Feb 05 '13 at 23:14
  • I see, didn't realize those existed. I personally wouldn't use them. – The Muffin Man Feb 05 '13 at 23:17
  • @Nick, agreed, they are time-bombs. – Josh Feb 05 '13 at 23:21

1 Answers1

2

jQuery deprecated the .live() method in v1.9. It can be replaced with .on(). This broke jquery.unobtrusive-ajax.js. I know from experience when cursing the update that I first pulled from NuGet.

There is an update to jquery.validate out there, also mentioned in this thread. But I have not validated it yet, jquery 1.9.1 is available as well.

For your questions...

  1. I think it is good practice to keep your packages upto date, but also research any deprecated functionality. Also using some source save like tools is a good idea. You could easily revert any breaking changes with one or two mouse clicks.

  2. Even though there is not a \packages folder added to you virgin project (intra or internet). If you open up the NuGet package manager UI, updates will still show up.

Community
  • 1
  • 1
cameronjchurch
  • 410
  • 3
  • 7
  • The first fix I made was replacing .live() with .on(). That seemed to work until I started testing a from and had received an error about not escaping characters. Same code that worked with the earlier versions. At that point I realized I would have to continue to modify jquery.unobtrusive-ajax.js and other libraries and get more out of sync. Of course without getting the Unit Tests and regression testing my changes, I thought it was best to leave the older versions. I agree with the goal of keeping packages up-to-date, but the work cross checking compatibility is huge. – Josh Feb 05 '13 at 22:08
  • FYI... I just updated all of the jQuery packages on my personal site without issue. Well... initially i received an error in IE for jquery.validate.js, but then I cleared my temp internet files. i think IE was still caching the old version of the bundles. Give it a try if your still running in to issues. NOTE... Chrome didn't throw the exception in the console though. Hope this helps. – cameronjchurch Feb 06 '13 at 01:08