开发者

Too many jquery plugins?

I'm developing a website, but I realized that, in addition to the link to my main javascript file, and the link to the jquery file, it's beginning to look like I'm going to have links to three or more plugins also. I'm just wondering if this is good practice? The site I'm building is a web app, so I need a lot of functionality, but I don't want to be a plugin glutton. Is it considered good to append all the javascript plugins together into one file so as to only have to download one file, or wil开发者_如何转开发l I run into problems?


If the plugins will be adding value to your site, I cannot see how that will be a problem. In general, plugins contain just enough code to do what they were meant to do. This makes their use quite a good practice when compared to using one monolithic library with plenty of unused functionality.

As for concatenating the JavaScript files together, that can help in terms of front-end loading performance, so I would recommend that.


Im working on the performance of a large corporate website that uses jQuery. We have found that a high number of connections can really kill performance.

There are three things you can do with your plugins

  1. Minify the javascript using Google Closure Compiler.
  2. Combine the minified js into one download called eg plugins.min.js
  3. Set up an alternate domain for serving js content eg http:/scripts.acme.com.

The minified js means it will download and parse faster, combined into one file will save some connections, and using a cookieless domain will reduce the data that has to be sent up to the server.

Using a CDN eg Google for the main jquery file is also a good idea.


Bad practice or not, if you consider yourself as developer you should think about whether to grab a plugin or do-it-yourself.

Of course one could state, why should I invent the wheel if somebody already did that in the past, but I'd always prefer to do things on my own if it's not a massive overkill.

I guess there are lots of advantages doing it yourself, like maintenance (knowing what's going on at all times), you increase your programming knowledge etc.

On the other hand, time is money so people could bring that into play. That of course is a good point nowadays. So maybe this whole topic comes down to a individual decision.


I use $.getScript() to load plugins on $(document).ready(). Don't know if its a good practice or not but it seems to slightly decrease the document load time and allows me to load plugins as deemed necessary.


your only problem will be maintenance re: upgrading versions. its a good idea to combine all your js together to reduce request overhead. I do this at deploy time


No Mate it is not good practice to bring plugin before you fully confirm to yourself the job can not be done easily you writing the code.

And even then always check the maintenance, reputation of the plugin writer and it's testability.

Plugins are code written by third party. No matter how good they are they are never customized to your needs (even with all the options parameters).

There are just way to many plugins out there that do so many simple things with 4 pages of JS. While spending 15min you can achieve exactly what you want in 10lines


Many sites require the use of large and often many JavaScript files. Whether this is in the way of plug-ins or custom scripts.

In this case I would suggest you look at performance of your application. For example minifying your JavaScript files and where possible send them to the client gzipped with expire headers so they can be cached.


Having jquery plugins in multiple files will allow you to only load those specific files needed for a given page. If all plugins are required for every page then this would not help.

Also, remember to use a jquery cdn so load times should be faster.

http://softwareas.com/google-jquery-cdn


Not sure what technologies you're using but I use http://github.com/jetheredge/bundler (ASP.Net/MVC) by Justin Etheredge.

very simple framework that I could leverage to combine my css and javascript without a lot of fuss

The JavaScript minifying and combining is handled by JSMin. Css compressing done with stock YUI compressor.

If you're using php am sure there will be some alternative :) As mentioned above using a cdn and reducing http requests can benefit your website.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜