4

If you choose to download a copy of jQuery, is it best practice to name it with a version identifier or without? That is to say, jquery-min.js versus jquery-1.10.2.min.js.

Clearly, the advantage of omitting the version identifier is that you don't have to change your source code when you upgrade. But the advantage of keeping it is that it's immediately obvious what the version is.

I'm curious what's the best practice here. I see that StackExchange hardcodes the link to Google APIs, and that they're still using version 1.7.1. If they were to upgrade, they'd have to do a "Replace All" on all their static files. Is this normal or undesirable?

ktm5124
  • 11,861
  • 21
  • 74
  • 119
  • If your not using CDN take a look at what sberry put in his answer. If you are using CDN what we do is set up a file called script-links.jspf (name according to the tech your using) and just include it at the bottom of all pages. That way you change it in the script-links.jspf and your good to go. – buzzsawddog Oct 03 '13 at 20:35
  • As a shop this is what we do... Setup a file named something like `script-links.jspf` Put your link to your jQuery in that file. Now include the script-links.jspf in each of your pages needing jQuery. I personally prefer the script-links option because I can at a glance look and tell what version of jQuery I am using! I don't have to take the time to open the file up and look at it. The same goes for any plugins or other script includes that you need. We include system level js in that file. – buzzsawddog Oct 03 '13 at 20:46
  • I cannot find it at the moment but I believe jQuery used to allow you link to their `jquery.latest.js` file but doing that could end up costing you because they are maintaining 1.10.x and 2.x in tandem so how do you know which "latest" file you are being served? 2.x dropped support for IE8 and lower so if that's important then "latest" might not be the best choice. I personally choose to specify the version in the filename. If you are worried about replacing all instances then I have one question for you: Are you not using a framework or at minimum an `include()` statement for your header? – MonkeyZeus Oct 03 '13 at 20:54
  • @MonkeyZeus the idea of jquery.latest.js is kind of scary when you are not in control of linking the latest part. One day you have written your site to work with someVersion and the next day latest points to anotherVersion and you now have untested functionality. – buzzsawddog Oct 03 '13 at 21:26

4 Answers4

3

You can possibly try like this:-

product-name.plugin-ver.sion.filetype.js

Example:-

  • jquery-1.4.2.min.js
  • jquery.plugin-0.1.js

Also check this related Thread

Community
  • 1
  • 1
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
2

One option would be to do a hard, or soft link on disk for jquery-min.js to jquery-version.min.js. Then if you update, you can just change the link.

sberry
  • 128,281
  • 18
  • 138
  • 165
  • I was about to say the same thing! This is likely the best option. Code never gets touched and you change the softlink when needed! Unless, your like us and you use the cdn... – buzzsawddog Oct 03 '13 at 20:33
0

There is no hard convention (like PEP 8) regarding the way you name your files.

It is beneficial, however, to retain the version number for scripts used in a large-scale project, such that the act of you introducing an upgraded JS library will not require re-testing of the entire system, only the parts of the system that make use of your library version.

Brian
  • 7,394
  • 3
  • 25
  • 46
0

asp.net bundling can handle this for you:

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js"));

In the case of a static link to a script (like a CDN), your app should probably be designed in such a way that there is only one place to change the reference.

Jason P
  • 26,984
  • 3
  • 31
  • 45