How to make jQuery links for updating Nuget in Visual Studio 2012

I have an ASP.net solution with jquery and on some pages, for example, I refer to this as follows:

<script type="text/javascript" src="Scripts/jquery-1.9.1.js"></script> <script type="text/javascript" src="Scripts/jquery-ui-1.10.2.js"></script> 

The problem is that Nuget has now updated jquery links to version 2.0 and not updated script links ... this happened with other JavaScript links ...

How can I link to these scripts, so when nuget updates them, it also updates links to related pages?

+4
source share
1 answer

This is a kind of indirect answer, but still a viable solution in many scenarios.


Updating NuGet Pages - Inappropriate

I do not believe that Nuget will be able to update anything on your pages. I do not believe that he has access to these operations. In addition, it is likely to be rather uncertain.


Using Grouping and Wildcards - Viable

This is the approach I would recommend. This requires an optimization package (which can be downloaded via NuGet). This reduces the number of queries made, which is always nice.

Essentially, you create script packages that let you merge multiple script files together (also works with CSS). The following is an example of a merge using the {version} wildcard.

 public class BundleConfig { public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/jquery") .Include("Scripts/jquery-{version}.js")); bundles.Add(new ScriptBundle("~/bundles/jqueryui") .Include("Scripts/jquery-ui-{version}.js")); } } 

Then you register the package in the Application_Start method in Global.asax.cs.

Finally, you can replace

 <script type="text/javascript" src="Scripts/jquery-1.9.1.js"></script> <script type="text/javascript" src="Scripts/jquery-ui-1.10.2.js"></script> 

with

 <%: Scripts.Render("~bundles/jquery") %> <%: Scripts.Render("~bundles/jqueryui") %> 

This will allow you to get the latest version of jQuery in your folders and use it, so you no longer have to change the links to the script.

Note : the string "~/bundles/jquery" can be called the way you want.
Note : This only works in .NET 4.5+ (Thanks to Kevin Jonsrud )
Link : Combining and minimizing in web forms

Also, while you really haven't asked about this, I feel obligated to mention this. These script links can be moved to MasterPage in a <head> block, which allows you to reduce code repetition (and align it with the DRY principle).

+3
source

Source: https://habr.com/ru/post/1481106/


All Articles