简体   繁体   English

我应该将JavaScript库的版本号放在文件名中吗?

[英]Should I put the version number of my JavaScript library in the file name?

I am about to release a javascript library. 我即将发布一个javascript库。

I would like to save the file as [library-name].1.0.0 我想将文件保存为[library-name] .1.0.0

Then as the library will evolve you will be able to download new versions, eg 然后随着库的发展,您将能够下载新版本,例如

  • [library-name].1.0.1.js [库名称] .1.0.1.js
  • [library-name].1.0.2.js [库名称] .1.0.2.js
  • [library-name].1.0.3.js [库名称] .1.0.3.js
  • [library-name].1.1.0.js [库名称] .1.1.0.js
  • [library-name].1.2.0.js [库名称] .1.2.0.js
  • [library-name].2.0.0.js [库名称] .2.0.0.js

My question is: is there any reason not to save the version in the name of the file? 我的问题是:有没有理由不在文件名中保存版本?

I am using other 3rd party libraries and the ones for which I don't store the version I always have to figure out if I have to upgrade or not. 我正在使用其他第三方库以及我没有存储的版本,我总是需要弄清楚我是否必须升级。

For instance, I use codemirror.js, and I always wonder if I am using the latest version. 例如,我使用codemirror.js,我总是想知道我是否使用最新版本。

If you are giving it for download, then its a good idea to have version number as part of file name. 如果您要下载它,那么最好将版本号作为文件名的一部分。 Also its a good idea to add version number along with the license info at the beginning of the file like jQuery does 另外一个好主意是在文件开头添加版本号以及许可信息,就像jQuery一样

Checkout - http://code.jquery.com/jquery-1.9.1.min.js 结帐 - http://code.jquery.com/jquery-1.9.1.min.js

Only case where you shouldn't add version number is when you are referencing a script file throughout your website - because you don't want to change all references whenever you update the script. 只有当您在整个网站中引用脚本文件时,才会出现不应添加版本号的情况 - 因为您不希望在更新脚本时更改所有引用。

I've never released any libraries myself, but putting the version number in the file name sounds like a fine idea to me. 我自己从未发布任何库,但将版本号放在文件名中对我来说听起来不错。

On upgrading, I think not putting the version number in the file name is used for libraries where the author doesn't expect to introduce breaking changes in future versions, only bug fixes and additions that don't affect code already written against the library. 在升级时,我认为将文件名中的版本号用于库,其中作者不期望在未来版本中引入重大更改,只修复错误并添加不影响已针对库编写的代码。 This means that people who use the library but don't host it themselves (ie who point to the library on a public CDN) automatically point to the latest version, and thus get bug fixes without having to do anything. 这意味着使用该库但不自己托管它的人(即谁指向公共CDN上的库)会自动指向最新版本,从而无需做任何事情就可以修复错误。

But, as you say, for people who download the library and host it themselves, it does mean they have to open the library file to check the version number. 但是,正如您所说,对于下载库并自行托管的人来说,这确实意味着他们必须打开库文件来检查版本号。

If you want to match what some other library publishers do, you might want to have a look at Semantic Versioning - it codifies the xxx version numbering system. 如果您想匹配其他库发布者所做的事情,您可能需要查看语义版本控制 - 它编写了xxx版本编号系统。

And if you're going to release your library through Github (which I believe is what the cool kids do these days), you might want to use Jonathan "Wolf" Rentzsch's system for doing semantic versioning there . 如果您打算通过Github发布您的库(我相信这些日子里很酷的孩子们),您可能希望使用Jonathan“Wolf”Rentzsch的系统在那里进行语义版本控制

If you are using unit tests you can make sure that the V1 unit tests all work fine against V2 before releasing the library. 如果您正在使用单元测试,则可以确保V1单元在释放库之前测试所有与V2完全正常的工作。

Smashing article on js unit testing 粉碎关于js单元测试的文章

如果我正确理解您的问题,不包含版本名称的一个原因是,如果您托管脚本,则使用该CDN托管文件的用户在升级时不必更改任何代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我应该在哪里放置JavaScript-页面或外部文件? - Where should I put my JavaScript - page or external file? 我应该在哪里放置我的JavaScript代码? - Where should I put my JavaScript code? 我应该把Javascript放在哪里? - Where should I put my Javascript in Wordpress? 我应该如何命名我的javascript库函数,以便它们可以与普通的旧javascript区分开来? - How should I name my javascript library functions so they are differentiable from plain old javascript? 我应该封装我的JavaScript库吗? - Should I encapsulate my javascript library? 我应该将对Java库的依赖关系串联起来吗? - Should I concatenate my dependencies on my Javascript library? 如果我只发布库的包,我应该将我的库依赖项放入 devDependencies 中吗? - Should i put my library dependencies into devDependencies if I only publish the bundle of the library? 我应该将 Javascript 放在 HTML 文件的头部还是正文中? - Should I Put Javascript in the Head or Body of an HTML File? 如何使用 javascript 从.apk 文件中获取签名、包名、版本号和版本名? - How to get signature, packagename, version number and version name from .apk file using javascript? 我应该将此JavaScript代码放入函数中吗? - Should I put this javascript code in a function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM