views:

24

answers:

2

I am using a number of jQuery plugins. Is it more efficient to reference them separately in the master page, or should I lump the contents of each file into a single jQueryPlugins.js file and reference that?

+1  A: 

The appropriate solution depends on your circumstances. A single file will reduce HTTP connections, decreasing latency. However, you may end up with wasted band-width.

It's a trade off you will need to determine.

Tim McNamara
A: 

No, it is not more effecient.

Opening and Closing TCP connections is more expensive in terms of bandwidth, than downloading content while a connection has been established.

You most likely want to lump it in a file as well as minify it, using either YUI Compressor or Google Closure Compiler when referencing it.

Moreover, if you wanted to get hyper conscious of your bandwidth, you could include the minified content inline within <script type="text/javascript"> </script> tags inside of your page.

Note also: once the user has downloaded the single file, provided you have set up the appropriate Expires Header, your code will be cached. That way you don't have to worry about referencing other files within your site or performance x-site.

Nirvana Tikku
I wouldn't embed the framework JavaScript directly inside `<script>` tags in the page if I were you -- it eliminates the possibility of caching, necessitating that the same JavaScript be downloaded with every page request (and not just the first one).
Cameron