从不必要/未使用的部分中剥离 JQuery:这可能吗?
是否可以只使用 JQuery 的一部分,就像使用 JQuery UI 一样:以简单的方式自定义自己的构建?
我的意思是想象你只需要 JQuery 库来在你的网站上提供一个愚蠢的、微小的但方便的工具,比如说对话框。
是否有可用的 JQuery 构建专门支持部分功能,而其代码大小只是当前 Javascript 代码大小的一小部分?
Is it possible to ONLY use portions of JQuery, just like with JQuery UI: customize ones own build in an easy way?
What i mean is imagine you ONLY need JQuery library for a silly, tiny but handy tool on youw site, lets say the Dialog boxes.
Are there JQuery builts available specifically supporting portions of functionality, at a fraction of the current Javascript code sizes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您的网站上只需要一小部分 jQuery,那么您很可能不需要 jQuery。您是否考虑过使用较小的库,例如 underscore 或 head.js?是否有一些关于 jQuery 的特殊功能是您需要的,而这些功能既不能手写,也不能在较小的库中找到?
jQuery 的缩小版本为 82kb,为了速度起见可以托管在 google 的 CDN 上。查看此页面的 CDN 托管 jQuery 部分:http://docs.jquery.com/Downloading_jQuery
If you only need a tiny portion of jQuery on your site, chances are good you don't need jQuery. Have you considered a smaller library such as underscore or head.js? Is there something particular about jQuery that you need that can't either be handwritten or found in a smaller library?
The minified version of jQuery is 82kb, and for speed's sake can be hosted on google's CDN. Check out the CDN Hosted jQuery section of this page: http://docs.jquery.com/Downloading_jQuery
你需要从相反的角度来思考。您需要的是删除死代码(即删除未使用的内容),而不是“包含已使用的内容”。
据我所知,唯一流行的死代码删除处理器是闭包编译器的高级模式。请注意,我不是谈论简单模式,它只进行缩小,而不是删除死代码或任何其他优化。
不幸的是,jQuery(尚)与闭包编译器的高级模式不兼容。
不过,您可以考虑使用 Dojo Toolkit,它在经过一定修改后与高级模式兼容。请在此处阅读。
如果您想使用流行的 JavaScript 库,但不想包含所有内容,您可以查看 Dojo。
仅很少使用核心功能的 Dojo 应用程序在使用高级模式编译后,可以减少到仅缩小版本(例如 Closure Simple 模式)大小的 40% 以下。
You need to think of it from the opposite angle. What you need is dead-code removal (i.e. remove things not used), not "include things that are used."
The only popular dead-code removal processor I know of is the Closure Compiler's Advanced Mode. Beware I am NOT talking about Simple Mode, which only does minification and not dead-code removal nor any other optimizations.
jQuery, unfortunately, is not (yet) compatible with the Closure Compiler's Advanced Mode.
However, you can consider the Dojo Toolkit, which is compatible with Advanced Mode after certain modifications. Read it here.
If you want to use a popular JavaScript library, but don't want to include everything, you can look into Dojo.
A Dojo application with only very light usage of the Core functions, after compiling with Advanced Mode, can be reduced to less than 40% of the size of a only-minified version (e.g. Closure Simple Mode).
据我所知没有。除了基于 css 的选择器,它被 sizzle 合并到 jQuery 中。但我确信您可以编写或找到仅具有您需要的功能的纯 js 库,并且如果您确实愿意的话可以跳过 jQuery。
Not that I know of. Except for css based selector which is sizzle incorporated into jQuery. But I am sure you can write or find pure js library that has only the functionality you need and skip jQuery if you really want to.
你可以在 jQuery 中使用: https://github.com/mythz/jquip
它是非官方的,尽管。
You can have at jQuery in pieces: https://github.com/mythz/jquip
It is unofficial, though.
您可以通过 Closure 编译器 提供 jQuery 和所有代码;这会删除您实际未使用的所有内容。但我不知道它会变小多少;它的内部可能是相互依存的。
You could feed jQuery plus all of your code through the Closure Compiler; that would remove everything you weren't actually using. I don't know how much smaller it would get, though; it might be all interdependent on the inside.