jQuery jquery的普通包和瘦包有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35424053/
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 are the differences between normal and slim package of jquery?
提问by SynCap
At CDNJSjquery.slim package is placed. It has a smaller size. What are the major differences from an original? A quick look at the code didn't bring the answer, and at the jquery.com I've not found any reference about slim
package.
在CDNJS中放置 jquery.slim 包。它的尺寸更小。与原版的主要区别是什么?快速查看代码并没有带来答案,在 jquery.com 我没有找到任何关于slim
包的参考。
So, what are the differences between jquery.js and jquery.slim.js ?
那么, jquery.js 和 jquery.slim.js 之间有什么区别?
采纳答案by Bhojendra Rauniyar
Looking at the code I found the following differences between jquery.js and jquery.slim.js:
查看代码我发现 jquery.js 和 jquery.slim.js 之间存在以下差异:
In the jquery.slim.js, the following features are removed:
在 jquery.slim.js 中,删除了以下功能:
- jQuery.fn.extend
- jquery.fn.load
- jquery.each // Attach a bunch of functions for handling common AJAX events
- jQuery.expr.filters.animated
- ajax settings like jQuery.ajaxSettings.xhr, jQuery.ajaxPrefilter, jQuery.ajaxSetup, jQuery.ajaxPrefilter, jQuery.ajaxTransport, jQuery.ajaxSetup
- xml parsing like jQuery.parseXML,
- animation effects like jQuery.easing, jQuery.Animation, jQuery.speed
- jQuery.fn.extend
- jquery.fn.load
- jquery.each // 附上一堆处理常见AJAX事件的函数
- jQuery.expr.filters.animated
- ajax 设置,如 jQuery.ajaxSettings.xhr、jQuery.ajaxPrefilter、jQuery.ajaxSetup、jQuery.ajaxPrefilter、jQuery.ajaxTransport、jQuery.ajaxSetup
- 像 jQuery.parseXML 一样解析 xml,
- jQuery.easing, jQuery.Animation, jQuery.speed 等动画效果
回答by Jannie Theunissen
The short answer taken from the announcement of jQuery 3.0 Final Release:
从jQuery 3.0 Final Release的公告中得到的简短回答:
Along with the regular version of jQuery that includes the ajax and effects modules, we're releasing a “slim” version that excludes these modules. All in all, it excludes ajax, effects, and currently deprecated code.
除了包含 ajax 和效果模块的常规 jQuery 版本外,我们还发布了一个不包含这些模块的“瘦身”版本。总而言之,它不包括 ajax、效果和当前已弃用的代码。
The file size (gzipped) is about 6k smaller, 23.6k vs 30k.
文件大小(gzipped)大约小 6k,23.6k vs 30k。
回答by gxclarke
At this time, the most authoritative answer appears to be in this issue, which states "it is a custom build of jQuery that excludes effects, ajax, and deprecated code." Details will be announced with jQuery 3.0.
这时候,最权威的答案出现在这个issue 中,它指出“它是一个自定义构建的 jQuery,它排除了效果、ajax 和弃用的代码”。详细信息将在 jQuery 3.0 中公布。
I suspect that the rationale for excluding these components of the jQuery library is in recognition of the increasingly common scenario of jQuery being used in conjunction with another JS framework like Angular or React. In these cases, the usage of jQuery is primarily for DOM traversal and manipulation, so leaving out those components that are either obsolete or are provided by the framework gains about a 20% reduction in file size.
我怀疑排除 jQuery 库的这些组件的理由是认识到 jQuery 与另一个 JS 框架(如 Angular 或 React)结合使用的情况越来越普遍。在这些情况下,jQuery 的使用主要用于 DOM 遍历和操作,因此去掉那些已经过时或由框架提供的组件,文件大小可以减少 20% 左右。
回答by ChrisW
The jQuery blog, jQuery 3.1.1 Released!, says,
jQuery 博客,jQuery 3.1.1 发布!, 说,
Slim build
Sometimes you don't need ajax, or you prefer to use one of the many standalone libraries that focus on ajax requests. And often it is simpler to use a combination of CSS and class manipulation for all your web animations. Along with the regular version of jQuery that includes the ajax and effects modules, we've released a “slim” version that excludes these modules. All in all, it excludes ajax, effects, and currently deprecated code. The size of jQuery is very rarely a load performance concern these days, but the slim build is about 6k gzipped bytes smaller than the regular version – 23.6k vs 30k.
苗条身材
有时您不需要 ajax,或者您更喜欢使用许多专注于 ajax 请求的独立库之一。通常,对所有 Web 动画使用 CSS 和类操作的组合更简单。除了包含 ajax 和效果模块的常规 jQuery 版本外,我们还发布了一个不包含这些模块的“瘦身”版本。总而言之,它不包括 ajax、效果和当前已弃用的代码。如今,jQuery 的大小很少成为负载性能问题,但瘦构建比常规版本小约 6k gzipped 字节 - 23.6k vs 30k。
回答by kiranvj
I could see $.ajax
is removed from jQuery slim 3.2.1
我可以看到$.ajax
从 jQuery slim 3.2.1 中删除
From the jQuery docs
来自 jQuery文档
You can also use the slim build, which excludes the ajax and effects modules
你也可以使用slim build,它不包括ajax和effects模块
Below is the comment from the slim version with the features removed
以下是删除了功能的超薄版本的评论
/*! jQuery v3.2.1 -ajax,-ajax/jsonp,-ajax/load,-ajax/parseXML,-ajax/script,-ajax/var/location,-ajax/var/nonce,-ajax/var/rquery,-ajax/xhr,-manipulation/_evalUrl,-event/ajax,-effects,-effects/Tween,-effects/animatedSelector | (c) JS Foundation and other contributors | jquery.org/license */
回答by Yehuda Schwartz
As noted the Ajax and effects modules have been excluded from jQuery slim the size difference as of 3.3.1 for the minified version unzipped is 85k vs 69k (16k saving for slim) or 30vs24 for zipped, it is important to note that bootstrap 4 uses the slim jQueryso if someone wants the full version they need to call that instead
如前所述,Ajax 和效果模块已从 jQuery slim 中排除。从 3.3.1 开始,解压缩的缩小版本的大小差异为 85k 与 69k(为 slim 节省 16k)或 30vs24 的压缩版本,重要的是要注意bootstrap 4 使用纤薄的 jQuery所以如果有人想要完整版本,他们需要调用它