jquery.js 和 jquery.min.js 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3475024/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the difference between jquery.js and jquery.min.js?
提问by gowri
What is the difference between jquery.min.js and jquery.js?
jquery.min.js 和 jquery.js 有什么区别?
Which one has support for all functions?
哪一个支持所有功能?
采纳答案by webnoob
They are both the same functionally but the .min one has all unnecessary characters removed in order to make the file size smaller.
它们在功能上是相同的,但 .min 删除了所有不必要的字符,以减小文件大小。
Just to point out as well, you are better using the minified version (.min) for your live environment as Google are now checking on page loading times. Having all your JS file minified means they will load faster and will score you more brownie points.
还要指出的是,您最好将缩小版本 (.min) 用于您的实时环境,因为 Google 现在正在检查页面加载时间。缩小所有 JS 文件意味着它们会加载得更快,并且会为您获得更多的巧克力点数。
You can get an addon for Mozilla called Page Speed that will look through your site and show you all the .JS files and provide minified versions (amongst other things).
您可以获得一个名为 Page Speed 的 Mozilla 插件,它会浏览您的网站并向您展示所有 .JS 文件并提供缩小版本(除其他外)。
回答by Darin Dimitrov
Both support the same functions. jquery.min.js
is a compressed version of jquery.js
(whitespaces and comments stripped out, shorter variable names, ...) in order to preserve bandwidth. In terms of functionality they are absolutely the same. It is recommended to use this compressed version in production environment.
两者都支持相同的功能。jquery.min.js
是jquery.js
(删除空格和注释,更短的变量名称,...)以保留带宽的压缩版本。在功能方面,它们完全相同。推荐在生产环境使用这个压缩版本。
回答by thomasrutter
jquery.js= Pretty and easy to read :) Read this one.
jquery.min.js= Looks like jibberish! But has a smaller file size. Put this one on your site.
jquery.js= 漂亮且易于阅读 :) 阅读这个。
jquery.min.js= 看起来像胡言乱语!但具有较小的文件大小。把这个放在你的网站上。
Both are the same in functionality. The difference is only in whether it's formatted nicely for readability or compactly for smaller file size.
两者在功能上是相同的。区别仅在于它是为了可读性很好地格式化还是为了较小的文件大小而紧凑。
Specifically, the second one is minified, a process which involves removing unnecessary whitespace and shortening variable names. Both contribute to making the code much harder to read: the removal of whitespace removes line breaks and spaces messing up the formatting, and the shortening of variable names (including some function names) replaces the original variable names with meaningless letters.
具体来说,第二个是minified,这个过程涉及删除不必要的空格和缩短变量名。两者都有助于使代码更难阅读:删除空格会删除使格式混乱的换行符和空格,并且缩短变量名(包括一些函数名)用无意义的字母替换原始变量名。
All this is done in such a way that it doesn't affect the way the code behaves when run, in any way. Notably, the replacement/shortening of variable and function names is only done to names that appear in a local scope where it won't interfere with any other code in other scripts.
所有这些都是以这样一种方式完成的,即它不会以任何方式影响代码在运行时的行为方式。值得注意的是,变量和函数名称的替换/缩短仅适用于出现在本地范围内的名称,不会干扰其他脚本中的任何其他代码。
回答by Jarek
Jquery.min.js is nothing else but compressed version of jquery.js. You can use it the same way as jquery.js, but it's smaller, so in production you should use minified version and when you're debugging you can use normal jquery.js version. If you want to compress your own javascript file you can these compressors:
jquery.min.js 只不过是 jquery.js 的压缩版本。你可以像 jquery.js 一样使用它,但它更小,所以在生产中你应该使用缩小版本,当你调试时你可以使用普通的 jquery.js 版本。如果你想压缩你自己的 javascript 文件,你可以使用这些压缩器:
- http://developer.yahoo.com/yui/compressor/
- http://code.google.com/intl/pl-PL/closure/compiler/
- http://jscompress.com/
- http://developer.yahoo.com/yui/compressor/
- http://code.google.com/intl/pl-PL/closure/compiler/
- http://jscompress.com/
Or just read topis on StackOverflow about js compression :) :
或者只是在 StackOverflow 上阅读关于 js 压缩的主题:):
回答by Xfile
In easy language, both versions are absolutely the same. Only difference is:
用简单的语言来说,两个版本完全相同。唯一的区别是:
min.js is for websites (online)
.js is for developers, guys who needs to read, learn about or/and understand jquery codes, for ie plugin development (offline, local work).
min.js 用于网站(在线)
.js 适用于需要阅读、学习或/和理解 jquery 代码的开发人员,即插件开发(离线、本地工作)。
回答by Kris van der Mast
Both contain the same functionality but the .min.js equivalent has been optimized in size. You can open both files and take a look at them. In the .min.js file you'll notice that all variables names have been reduced to short names and that most whitespace & comments have been taken out.
两者都包含相同的功能,但等效的 .min.js 已在大小上进行了优化。您可以打开这两个文件并查看它们。在 .min.js 文件中,您会注意到所有变量名称都已简化为短名称,并且大部分空格和注释都已删除。
回答by PeterWong
jquery.js: when you have to dive into jquery's source code jquery.min.js: compressed version for saving bandwidth
jquery.js:当您必须深入研究 jquery 的源代码时 jquery.min.js:用于节省带宽的压缩版本
There is one more option for saving more bandwidth then the compressed version which is using something like Google CDN provided: http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
与使用 Google CDN 之类的压缩版本相比,还有一种可以节省更多带宽的选项:http: //ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
回答by Sebastian Lasse
summary - popular js frameworks like jquery or dojo offer one commented, pretty formatted version with comments for DEVELOPMENT and a minified version (quicker) without comments etc. for PRODUCTION
摘要 - 流行的 js 框架,如 jquery 或 dojo,提供了一个带注释的、格式漂亮的版本,其中包含针对 DEVELOPMENT 的注释,以及一个没有注释的缩小版本(更快)等用于 PRODUCTION
jquery.js - development jquery.min.js - production
jquery.js - 开发 jquery.min.js - 生产
回答by Ayush Sugandhi
If you're running JQuery on a production site, which library should you load? JQuery.js or JQuery.min.js? The short answer is, they are essentially the same, with the same functionality.
如果您在生产站点上运行 JQuery,您应该加载哪个库?JQuery.js 还是 JQuery.min.js?简短的回答是,它们本质上是相同的,具有相同的功能。
One version is long, while the other is the minified version. The minified is compressed to save space and page load time. White spaces have been removed in the minified version making them jibberish and impossible to read.
一个版本很长,而另一个是缩小版本。minified 被压缩以节省空间和页面加载时间。缩小版中的空格已被删除,使它们变得乱七八糟且无法阅读。
If you're going to run the JQuery library on a production site, I recommend that you use the minified version, to decrease page load time, which Google now considers in their page ranking.
如果您打算在生产站点上运行 JQuery 库,我建议您使用缩小版本,以减少页面加载时间,Google 现在在其页面排名中考虑了这一点。
Another good option is to use Google's online javascript library. This will save you the hassle of downloading the library, as well as uploading to your site. In addition, your site also does not use resources when JQuery is loaded.
另一个不错的选择是使用 Google 的在线 javascript 库。这将使您免于下载库以及上传到您的网站的麻烦。此外,您的站点在加载 JQuery 时也不使用资源。
The latest JQuery minified version from Google is available here.
谷歌最新的 JQuery 缩小版可在此处获得。
You can link to it in your pages using:
您可以使用以下方法在您的页面中链接到它:
http://ulyssesonline.com/2010/12/03/jquery-js-or-jquery-min-js/
http://ulyssesonline.com/2010/12/03/jquery-js-or-jquery-min-js/
回答by Hitesh
If you use use the Jquery from Google CDN, seriously it will improve the performance by 5 to 10 times the one which you add into your page, which gets downloaded. And also, you will get the latest version of the Jquery files.
如果您使用 Google CDN 中的 Jquery,那么与您添加到页面中并被下载的页面相比,它的性能会提高 5 到 10 倍。而且,您将获得最新版本的 Jquery 文件。
The difference between both files i.e. jquery.js and jquery.min.js is just the file size, due to this the files are getting downloaded faster. :)
这两个文件之间的区别,即 jquery.js 和 jquery.min.js 只是文件大小,因此文件下载速度更快。:)