What are the differences between normal and slim package of jquery?
在cdnjs jquery.slim包中。它的尺寸较小。与原作的主要区别是什么?在jquery.com上,我没有找到任何关于
那么,jquery.js和jquery.slim.js有什么区别?
jquery 3.0最终版本发布后的简短回答:
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.
文件大小(gzipped)大约小6K,23.6K对30K。
查看代码,我发现jquery.js和jquery.slim.js之间存在以下差异:
在jquery.slim.js中,删除了以下代码功能:
此时,最权威的答案似乎出现在这个问题中,它指出"它是jquery的自定义构建,不包括效果、Ajax和不推荐使用的代码。"详细信息将通过jquery 3.0公布。
我怀疑排除jquery库中这些组件的理由是认识到jquery与另一个JS框架(如angular或react)结合使用的场景越来越常见。在这些情况下,jquery的使用主要是为了进行DOM遍历和操作,因此除去那些过时的或由框架提供的组件,文件大小将减少大约20%。
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.
我可以看到jquery slim 3.2.1中删除了
下面是删除了这些功能的精简版的评论
1 | /*! 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 */ |
如前所述,jquery slim中排除了ajax和effects模块。从3.3.1开始,解压的迷你版本的大小差异为85k与69k(16k节省为slim)或30vs24,注意bootstrap 4使用了slim jquery,因此如果有人想要完整的版本,他们需要调用它。