JavaScript 缩小不会损害开源吗?
如今,网络上有很多关于缩小 JavaScript 的重要性的内容。速度才是最重要的。
但是缩小难道不会违背开源的开放性吗?
JS(相对于 flash 和后端)的一大优点是源代码就在那里,可供其他开发人员查看,他们会想“嘿,这看起来不错,我想知道他们是如何做到的”做到了”。 JS 源代码可供所有人查看,因此开发人员可以从中学习、改编并在自己的项目中使用类似的 JS。
缩小 JS 使其不可读。它阻止外部开发人员阅读代码,从而取消横向共享和学习。
显然,有些人希望缩小他们的 JS,其明确目的是试图保留他们的知识产权。当人们破坏开源社区的创造力时,这总是一种耻辱,但这在某种程度上是可以理解的,而且肯定不会停止。
但对于我们其他开发人员 - 那些每天都使用开源的人 - JS 缩小阻碍了我们。它使我们无法利用网络的开放性。它关闭了创意共享的可能性。
我热衷于缩小一些东西——库、插件等(也许还有向移动设备提供 JS 服务时)。但对于使您的个人网站个性化的定制代码,缩小您的代码确实没有必要。它可能会节省几毫秒的下载时间,但保持打开状态不会有太大变化。大多数 Web 站点的自定义 JS 代码可能都少于 20KB,而缩小这些代码的好处实际上微乎其微。几毫秒的时间真的能与保持 JS 代码开放、可读和可供其他人使用的好处相比吗?
对于拥有更多 JS 的网站,也许我们可以开始开发一个基于开源的标准,以便开发人员可以输入稍微不同的 URL,以便获得未压缩的代码。如果缩小后的代码位于domain.com/script.min.js,那么让我们在domain.com/script.js 或/script.full.js 上始终提供未缩小的代码。或者还有其他建议吗?
我在网上找不到任何其他关于这个问题的内容。一切都在另一边——推动缩小。这让我感到震惊。这让我觉得,作为开发人员,我们已经让自己陷入了一种不容置疑的速度意识形态,而不管其他因素如何。也许,由于意识形态的本质,你们中的一些人读到这篇文章会立即想要驳斥它并反对它。但再想一想 - 微小的速度优势真的值得牺牲开源创造力吗?我不相信是这样。
所以我想我的问题是,关于开源 JavaScript 的争论在哪里?
There's an awful lot on the web these days about how important it is to minify your JavaScript. Speed is all that matters.
But doesn't minification work against the openness of Open Source?
One of the great things about JS (as opposed to flash and the back-end) is that the source code is right there, available to be viewed by other developers who come along and think "Hey, that looks good, I wonder how they did that". The JS source code is available for everyone to see, and so developers can learn from it, adapt it, and use similar JS on their own projects.
Minifying JS makes it unreadable. It stops the external developer from being able to read the code, and so cancels out horizontal sharing and learning.
Obviously there will be some who wish to minify their JS for the express purpose of attempting to hold on to their intellectual property. It's always a shame when people undermine the creativity of the open-source community, but it's somewhat understandable, and certainly not going to stop.
But for the rest of us developers - the people who use open-source every day of our lives - JS minification gets in our way. It makes us unable to take advantage of the openness of the web. It closes down the possibility of creative sharing.
I'm all about some things being minified - libraries, plugins, etc (and maybe when serving JS to mobile). But for the custom-built code that makes your individual website individual, minifying your code is really not that necessary. It may save a few ms of download time, but keeping it open won't change that much. Most of the sites on the web probably have less than 20KB of custom JS code, and the benefit of minifying that really is minimal. Do a few ms really compare with the benefit of keeping JS code open, readable and available for others?
For sites with more JS, maybe we could start to develop an open-source-based standard, so that developers can type in a slightly different URL in order to be served the unminified code. If the minified code is at domain.com/script.min.js, let's make the unminified always available at domain.com/script.js or /script.full.js. Or are there other suggestions?
I can't really find anything else on the web talking about this issue. Everything is on the other side - pushing minification. And that alarms me. It makes me think that, as developers, we've allowed ourselves to sink into an unquestioned ideology of speed, regardless of other factors. And probably, because of the nature of ideology, some of you reading this will immediately want to dismiss it and argue against it. But think just a little bit longer - is the tiny speed benefit really worth the loss of open-source creativity? I don't believe it is.
So I guess my question is, where's the debate about open-source JavaScripting?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我很确定大多数(如果不是全部)提供缩小版本的开源 JavaScript 库也为开发人员提供了可以使用的原始源代码。这就像分发通用编译二进制文件的开源程序也将其原始源代码分发给公众一样。
如果您指的是专门针对某个项目针对每个项目制作的自定义脚本,则这些脚本默认情况下不是开源的,除非作者特别引用/包含 FOSS 许可声明。为此,我没有义务提供自定义代码的未缩小版本,除非我打算自由分发它并对其进行许可。
I'm pretty sure most — if not all — open source JavaScript libraries that offer minified versions also offer the original sources for developers to work on. It's just like how open source programs that distribute compiled binaries for general use also distribute their original sources to the public.
If you're referring to custom scripts made on a per-project basis specifically for a certain project, those scripts are not open source by default unless the author specifically cites/includes a FOSS license notice. To that end, I'm not obliged to provide an unminified version of my custom code unless I intend to distribute it freely and license it as such.
如果 javascript 是开源的,那么您还可以找到未缩小的版本。例如 jQuery:
http://docs.jquery.com/Downloading_jQuery
既有“minified”又有“minified” “未压缩”文件可供下载。
如果您发现一个声称是开源的 javascript 文件并且没有可用的未压缩文件,那么就犯了一个错误。
If the javascript is meant to be open source then you will also be able to find the un-minified version. For example, jQuery:
http://docs.jquery.com/Downloading_jQuery
There are both "minified" and "uncompressed" files for download.
If you find a javascript file which claims to be open source and does not have the uncompressed file available, then a mistake has been made.
因为没有争论;我还没有看到很多(任何?)FOSS JS 库没有非缩小版本。
即使有,FOSS 也不意味着可读——即使是未缩小的代码也可能完全难以辨认。
Because there's no debate; I haven't seen many (any?) FOSS JS libs that don't have a non-minified version.
Even if there was, FOSS doesn't mean readable--even non-minified code can be completely illegible.
我不认为我们真的想鼓励从随机偶然发现的网站源代码中学习 Javascript。如果你想学习 Javascript,最好从实际的开放网站中学习 99% 的情况下,
如果我不开源一段 JS,那不是因为知识产权问题,而是因为它速度很快。 hack - 不适合社区消费
无论节省的是 2kb(顺便说一句,这仍然有区别)还是 2mb,缩小都是最佳实践,应该从一开始就灌输给开发人员。
I don't think we really want to encourage the practice of learning Javascript from the source of websites stumbled upon randomly. If you want to learn Javascript, it's much better to learn from an actual open source project that's been documented, tested and written with care.
99% of the time if I don't open-source a piece of JS, it's not because of intellectual property concerns. It's because it's a quick hack - not suitable for community consumption
Whether or not the saving is 2kb (which still makes a difference, incidentally) or 2mb, minification is a best practice, and should be instilled in developers from the get-go.