Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blend multiple jQuery files - Best practice?

I'm starting to learn JavaScript and jQuery. I managed to do some tweakings and stuff, everything's fine so far. But I was thinking if it is a best practice to mix multiple jQuery files and plugins. For example:

I have jQuery 1.3.2 min.js, jQuery easing 1.3.js, jQuery Cycle min.js and jQuery UI. Would it be recommended to put together jQuery (main), jQuery easing and jQuery cycle in just one file?

Please give me some light here.

Thanks,

like image 462
Vitor Avatar asked Dec 30 '09 17:12

Vitor


2 Answers

Keep the files separate and use your back-end to minify and gzip them as part of your deploy process. As others have mentioned this will save your users making unnecessary requests and it will save you having to maintain a huge ugly file.

The added benefit here is that you can actually keep the verbose, commented, full files for all of these in your source tree (for reading/etc) while serving the compressed ones to users.

like image 131
rfunduk Avatar answered Oct 26 '22 10:10

rfunduk


You can do so. It saves the amount of HTTP requests to haul all the JS code in. It is only a bit harder to maintain, but in my opinion it doesn't outweigh the benefits you (and the client!) have with less HTTP requests.

If you're using a server side language and good deployment tools, you can even automate the minifying and merging of JS files before publishing. We also do it here with a little help of YUI Compressor and a few lines of Java code in a batch application. Works great, the endusers have the benefit of less HTTP requests and the developers have the benefit of not doing all that merging and maintainence manually.

like image 5
BalusC Avatar answered Oct 26 '22 09:10

BalusC