Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

Minification problem

posted by theyouyou 8 years ago

the Flourish JSMin version caused me javascript errors (unterminated string litteral)

The Minify JSMin version doesn't: http://code.google.com/p/minify/source/browse/trunk/min/lib/JSMin.php
"Minify uses an enhanced port of Douglas Crockford's JSMin library and custom classes to minify CSS and HTML"

Should I open a ticket?

theyouyou - it may be the case that JSMin.php is actually the one with the error (although it is unclear since we can't see your code or the difference between the outputs). To determine if this is the case, you could compile Crockford's actual C implementation: http://www.crockford.com/javascript/jsmin.c and run it through manually (then test it).

I can tell you from my own playing around with various minification algorithms and mechanisms that badly formed javascript can cause this. You may want to run your non-minified JS through a linter to catch common errors.

If I'm not mistaken, that error is most commonly caused by an assignment not terminated with an ;

Examples:

var foo = function () {

}  // This should have a ; at the end.

var bar = {
  'foo' : foo
}  // This should also have a ; at the end.

These go commonly unnoticed, particularly on longer functions or objects because the bracket notation will often mean the end of an if, for, while, statement -- where it obviously is not required.

posted by mattsah 8 years ago

Thank you msahagian.

Sorry the code is a little bit long, but I didn't manage to get the exact part that causes the problem I can't see any ';' missing, do you ?


// Sammy
var sammy = $.sammy(function() {



});
// End of Sammy

$(document).ready(function(){

	$('.contentChild').equalHeightColumns();

	// Init
    // sammy.run("#!/search");
	
	// Dropdown
	$("#tabAccount a").click( function() {
		toggleAccountDropdown();
	});
	
	// General
	$(".radioButton").click( function() {
		$(this).parent().find('.radioButton').prop("disabled", false).removeClass("toggled");
		$(this).addClass("toggled").prop("disabled", true);
	});
	$(".toggleButton").click( function() {
		$(this).toggleClass("toggled");
	});
	$('[placeholder]').defaultValue();
	// End of General


	
	
});
posted by theyouyou 8 years ago

Your code looks fine, but I'd be curious to know what is contained in the following methods:

toggleAccountDropdown() and the .equalHeightColumns() on the jQuery object.

I did a quick scan of some source which I found and presume is the same .equalHeightColumns() stuff you're using, and didn't see too much to worry about. This all being said, there are probably a number of other minor syntax issues which could cause the minified JS to be a problem -- or it could legitimately be a bug.

Is the site that this is on public in any way? I.e. can I go there and see the syntax error so I can try and trace it back myself?

I believe firebug will give you some nice context in the console on JS syntax errors which can be helpful if you are having an issue with the minified code but not the non-minified version.

Obviously debugging minified code is more difficult because all your stuff tends to be on one, two, or three lines at most usually.

If you care to go through the trouble of providing all the JS code:

  • jQuery version
  • Exact source of plugin for equal height columns
  • Missing source for the toggleAccountDropdown() function
  • etc

I can gladly attempt to recreate this and help with the debugging. Also, just to mention again, it may be worth trying to run all of this through the original jsmin.c and using that manually minified code.

posted by mattsah 8 years ago

Thank you again msahagian but I doubt that it's really worth it, IMHO.

I may have to convert some of my old flatten php projects into MVC OOP style, with the Flourish Framework (or not). So I would spend a lot of time debugging my JavaScript which actually works fine when it's minified with Minify.

Since my last message, I implemented the Minify Class which doesn't cause any problem. http://code.google.com/p/minify/wiki/CustomServer

posted by theyouyou 8 years ago