CDN jQuery with lot of uneccessary functions or own FTP jQuery with less functions?
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?
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
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
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.
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
精彩评论