CDN jQuery 具有很多不必要的功能,还是自己的 FTP jQuery 功能较少?
我刚刚从上一个问题中弄清楚如何将自定义函数/插件添加到 jQuery 如何从 CDN 扩展 jQuery?。现在,我的问题是,如果 jQuery 中的某些功能对于页面来说不是必需的怎么办?我决定删除这些功能,稍后在需要时添加它们。但是,如果我删除它们,我就不能将 Google 的 CDN 用于我的 jQuery,我现在确信可以从 CDN 扩展 jQuery,但我不认为我可以删除其中的某些功能。
问题:
哪一个更好(在任何方面),来自 CDN 的带有许多不必要功能的 jQuery 或我自己的 FTP 上的 jQuery,通过删除不必要的功能来减小大小?
如果我自己的FTP上修改/减少的jQuery更好,如何正确删除这些功能?有哪些冲突?或者是否有函数依赖于另一个函数?
如果来自 CDN 的 jQuery 更好,您认为哪个服务器提供的最好?
I just figured out how to add custom functions/plug-ins to jQuery from my previous question How to extend jQuery from CDN?. Now, my question is, how if some functions in jQuery isn't necessary for the page? I've decided to remove those functions and just add them later on if I need them. But, if I'll remove 'em, I cannot use Google's CDN for my jQuery, I'm certain now that it is possible to extend the jQuery from CDN, but I don't hink I can delete some functions there.
Questions:
Which is better(in any aspect), a jQuery from CDN with lot of uneccessary functions or a jQuery on my own FTP with reduced size(by removing uneccessary functions)?
If a modified/reduced jQuery on my own FTP is better, how to remove those functions properly? What are the conflicts? Or are there functions dependent to another functions?
If a jQuery from a CDN is better, in your opinion, which server has the best to offer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
无论您是否在自己的 FTP 中减小 jQuery 的大小,通常您都不想通过手动删除不必要的函数来修改 jQuery 库,除非您了解 jQuery 的依赖结构图书馆(我想我们都没有)。因此,如果我是你,我会坚持使用 CDN 中的 jQuery。
正如我所说,修改像 jQuery 这样的巨大代码库是非常困难的,几乎不可能,即使使用 YUI 压缩器或 google 闭包编译器等压缩工具也是如此。你不想不惜一切代价这样做。
据我所知,google还是比较靠谱的。不过,这里给你一些建议:
-Microsoft CDN 与 Google CDN
-为何选择 Google CDN
Whether you reduce the size of the jQuery or not in your own FTP, Normally you dont want to modify the jQuery library by manually removing the unnecessary functions unless you have a knowledge over the dependency structure of the library (which I think we all dont). Therefore, I would just stick to jQuery from CDN in your case if I were you.
As I said, it is very hard and almost impossible to modify a huge code library such as jQuery, even using minifier tools such as YUI compressor or google closure compiler..So, Again; You do not want to do that at any cost.
As far as I know, google is quite reliable. However, here are some suggestions for you:
-Microsoft CDN vs Google CDN
-Why Google CDN
我给你我的意见。如果您的 ftp 源与您的 Web 服务器位于同一台,请选择您的 FTP 源,如果位于不同的服务器中,请选择 CDN。为什么?可靠性。您的服务器比 CDN 服务器更有可能崩溃。但是,如果在同一台服务器上,cdn 失败的可能性更大(例如,如果互联网服务失败),并且如果您的服务器死了,所有系统都会死(库+您的网络代码),您明白吗? 链条的强度取决于最薄弱的一环。
但是,修改 jquery 源时要小心,这有点危险,除非您对修改后的源进行广泛的单元测试。问题是每次 jquery 更新时你都必须修改它。
只是我的2分钱。
希望这有帮助。干杯
I'll give you my opinion. If your ftp source is in the same as your web server, go for your FTP source, If it's in a different server, go for CDN. Why? Reliability. It's more probable for your server to fall than a CDN server. But, if it's on the same server, It's more probable for the cdn to fail (for example, if the internet service fails), and if your server dies, all the system dies (libraries + your web code), do you understand? A chain is only as strong as the weakest link.
But, be careful when modifying the jquery source, it's a bit dangerous, unless you do extensive unit testing to the modified source. and the problem is that you'll have to modify it everytime jquery gets updated.
Just my 2 cents.
Hope this helps. Cheers
我使用 CDN 托管 jquery 的主要原因之一是因为我的用户可能已经缓存了它。
如果他们访问过使用相同 CDN 和 CDN 的任何其他网站,文件作为您的站点,该文件将已经缓存在用户的计算机上(浏览器设置除外)。
正如罗布所说,另一个原因是延迟。
当您从 CDN 请求文件时,它会选择离您最近的服务器(或者可能只是最快的服务器)并从那里传送文件。这有助于在不同的地理位置提供更一致的加载速度。
One of the main reasons I use CDN hosted jquery is because it's likely that my users already have it cached.
If they have been to any other site that uses the same CDN & file as your site, the file will already be cached on the user's machine (browser settings aside).
The other reason, as Rob stated, is latency.
When you ask for a file from a CDN, it selects the closest server to you (or maybe just the fastest) and delivers the file from there. This can help provide a more consistent loading speeds from varying geographical locations.
这些都是很好的资源:
雅虎的加速网站速度的最佳实践
和
加载脚本而不阻塞。
除非您使用自己的 CDN(例如,通过 Amazon Cloud),否则我怀疑您经过手术最小化的 jQuery 版本是否会下载得更快 - 真正重要的是服务器的延迟。我同意本尼的观点,即修改库是一个正式的坏主意。
这个问题稍微有点扭曲...如果你可以将 jQuery 与你的应用程序特定的 javascript 文件结合起来,效果会更好吗?通过组合 javascript 文件,您可以满足第一个 YSlow 规则“最小化 HTTP 请求”,但代价是忽略第二个“使用 CDN 网络”。我经常想知道哪个更好。
青年MMV
These are good resources:
Yahoo's Best practices for speeding up a web site
and
Loading scripts without blocking.
Unless you're using your own CDN (e.g., via Amazon Cloud), I would doubt your surgically minimized version of jQuery would download faster - it's the latency to the server that really matters. And I agree with Benny that modifying the library is an officially bad idea.
A slight twist on the question...If you could combine jQuery with your app specific javascript files, would that perform better? By combining javascript files you satisfy the first YSlow rule "Minimize HTTP Requests", but at the expense of ignoring the second "Use CDN networks". I have often wondered which is better.
YMMV