问题描述
有人知道一个工具可以告诉我给定页面使用哪些JQuery函数吗?我想将包含的文件减少到最低限度.谢谢.
Does anyone know of a tool that will tell me which JQuery functions are being used for a given page? I'd like to trim down the included files to just the bare minimum. Thanks.
推荐答案
我不认为您会走这条路,因为它将为您提供非常很少的好处(并且您可能会尝试刺入自己的眼睛).让我分别介绍您在评论中提到的2个软件包.
I don't think you'll want to go down this road, as it'll provide you very little if any benefit (and you may stab yourself in the eye trying to do it). Let me cover the 2 packages you mentioned in comments here separately.
jQuery Core 已经很小,如果您使用的是缩小版,并且通过gzip (和服务) ),那么jquery仅为 24kb (从当前的1.4.2版本开始).
jQuery Core is pretty small already, if you're using the minified version and serving it via gzip (and you should be doing this) then jquery is only 24kb (as of the current 1.4.2 release).
jQuery UI 但是有点麻烦,您可以精简所需的效果和小部件通过在此处使用其下载管理器,只需选择所需的组件,将其余组件保留下来,即可获得所需的缩小/精简版本.
jQuery UI however is a bit heftier, you can strip down to the effects and widgets you need by using their download manager here, just select the components you need, leave the rest off, and get a minified/stripped down version that you want.
第2部分:替代方法
另一个为用户提供更好体验的替代方法是包括CDN中的脚本,例如,以下是Google CDN的链接:
Another alternative to give your users a better experience would be to include your scripts from a CDN, for example here are the links for Google's CDN:
- jQuery: http://ajax.googleapis .com/ajax/libs/jquery/1.4.2/jquery.min.js
-
jQuery UI: http ://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js
看看如何在CSS中也包含CSS的问题 a>(如果您使用的是默认主题之一,请修改URL中的版本号以匹配所使用的脚本)
You can also modify these a bit, depending how up-to-date you want to be, for example:
- 最新的jQuery 1.4.x: http://ajax .googleapis.com/ajax/libs/jquery/1.4/jquery.min.js
- jQuery 1.x最新版本: http://ajax .googleapis.com/ajax/libs/jquery/1/jquery.min.js
- jQuery UI 1.8.x最新版本: http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js
- jQuery UI 1.x最新版本: http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js
- jQuery 1.4.x latest: http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js
- jQuery 1.x latest: http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
- jQuery UI 1.8.x latest: http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js
- jQuery UI 1.x latest: http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js
出于为什么使用CDN的原因,.
For reasons on why to use a CDN, take a look at this question.
这篇关于判断需要哪些JQuery函数的简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!