3

In MVC 4, using the Bundles to define the files you want to include, you can use a {version} wildcard, for example...

"~/Scripts/jquery-{version}.js"

This works well when you have one version in the folder, e.g. jquery-1.7.js. However, when we have two versions in the folder jquery-1.7.js & jquery-1.9.js, it seems to pick up the old version, ignoring the new version.

Does the {version} wildcard find the first instance, and then move on? if so, the first instance in this example seems to the be the old version (as 1.7 comes before 1.9). So, is there a way of forcing it to look for the newest version if we have two files?

NOTE: The above version numbers may not be accurate, just used for scenario purpose.

Christian Phillips
  • 18,399
  • 8
  • 53
  • 82
  • 1
    Some info already discussed here: http://stackoverflow.com/questions/12029161/version-wildcard-in-mvc4-bundle – SkyBlues87 Sep 17 '13 at 08:54
  • It doesn't really answer the question, **Can we force it to get the latest version?** if the answer is to make sure your scripts directory only has the version you want to use, then that's fine, but I just wanted to check with others who may have come across the same issue. – Christian Phillips Sep 17 '13 at 09:22
  • This comment from the other discussion should be clear enough: "It's [{version} is] a regex so it would include all matches, so if you had multiple versions in the same directory you probably would not want to use this." If that is true then I'd guess both versions are being included, and the last one that loads is overwriting/mangling the code that loads before it. You can verify that by running with debug="true" in web.config and viewing the html that is output from a page. – Jeremy Cook Sep 23 '13 at 20:49
  • @JeremyCook, you can use firebug / chrome tools to see what has been loaded - and I can verify that the old one was being loaded. I'm just wondering if we can force it to load latest. – Christian Phillips Sep 23 '13 at 20:52
  • You can using an IBundleOrderer ala http://stackoverflow.com/questions/14563415/force-asp-net-mvc-bundle-to-render-the-javascript-files-in-a-certain-order Haven't used one myself. Personally, I'd consider manually specifying what the scripts or putting the older script in a separate folder. – Jeremy Cook Sep 23 '13 at 21:05
  • So you want both to load on the same page? – Jeremy Cook Sep 23 '13 at 21:07

2 Answers2

1

In Mvc. It will load the old version first and then latest version. following will be sequence of jquery file load. 1.jquery-1.7.js 2.jquery-1.9.js

In this situation . latest file will overwrite the old version. so your page always get latest jquery functionality.

0

We ended up using something similar to this post, which tackles a similar issue. I will update the answer with a full description and code in the next few weeks once implemented fully.

Christian Phillips
  • 18,399
  • 8
  • 53
  • 82