What's the difference between jquery.js and jquery.min.js?
What is the difference between jquery.min.js and jquery.js?
Which one has support for all functi开发者_开发技巧ons?
They are both the same functionally but the .min one has all unnecessary characters removed in order to make the file size smaller.
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.
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).
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.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.
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.
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.
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:
- 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 :) :
- Best JavaScript compressor
- What do you use to minimize and compress JavaScript libraries?
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).
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.
jquery.js: when you have to dive into jquery's source code jquery.min.js: compressed version for saving bandwidth
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
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
jquery.js - development jquery.min.js - production
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.
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.
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.
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.
You can link to it in your pages using:
<script type=’text/javascript’ src=’http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js‘></script>
jquery.min is compress version. It's removed comments, new lines, ...
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.
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.min.js
: this is the minified version of jQuery.
jquery.js
: this is the regular version of jQuery.
By using minified
version of files following advantages could be experienced hence better use it in your application.
- It will drastically reduce loading times and bandwidth usage on your website.
- It also improves site speed and accessibility, directly translating into a better user experience.
Minification
has become standard practice for page optimization.
Developers tend to use spacing, comments and well-named variables to make code and markup readable for themselves. This is a plus in the development phase, it becomes a negative when it comes to serving your pages. When minified, comments and extra spaces will be removed saving up file size and reducing bandwidth of network.
Therefore, basically the functionality is exactly the same except the readability.
精彩评论