niggles
niggles

Reputation: 1034

Javascript concat/minify libraries that work with Jquery?

I've tried a number of dynamic Javascript minifying / concatenating libraries, but they all seem to have the problem that anything that requires Jquery in the $(document).ready() command ends up saying "$ is not defined", even if they're included in the list of files to be concatenated.

I can get around this by leaving Jquery out of the concatenation (and CUFON and anything else that relies on $(document).ready() ), but this is obviously not ideal.

Any suggestions on how to make them happily play together so I can reduce the loading to 1 file, but still have Jquery available to the scripts that need it?

Upvotes: 0

Views: 1046

Answers (3)

Dale Anderson
Dale Anderson

Reputation: 1701

I've successfully minified jQuery using Microsoft's AjaxMin. This is the minifier that is used out of the box by PackScript, an awesome tool for managing the whole web resource build process.

Check it out - http://danderson00.blogspot.com.au/2013/01/packscript-next-generation-build-for-web.html

Upvotes: 0

Robert Koritnik
Robert Koritnik

Reputation: 105039

I use this web site for static javascript file compression. Never had any problems with YUI compressed scripts. Always worked as expected.

But it's true I'm using jQuery's minified file. I don't minify it myself. I minify my own plugins and scripts and they work with jQuery.

And for the sake of brevity I always use:

$(function() {
    // ready script
});

instead of:

$(document).ready(function() {
    // ready script
});

Upvotes: 0

niggles
niggles

Reputation: 1034

After some further research I found that head.js works a treat - it just requires replacing $(document).ready() calls with head.ready() calls and everything plays happily together :-)

Upvotes: 1

Related Questions