Optimization javascript with JSMin.

CommentFileSizeAuthor
javascript_aggregator.zip5.45 KBM@ster
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

derjochenmeyer’s picture

Thanks a lot!!! .. i will probably work this into a new version if tests go well ...

Edit: It requires PHP 5 to work + the licence of the jsmin.inc is not GPL but MIT ... i think that would make it necessary to download the jsmin.inc seperately if i worked this into a release! Because all code included in Drupal distributions has to be under the GPL licence.

Edit2: However, if you want to try optimization with jsmin just extract this zip-file and install/enable like a normal module release.

There is some more info about jsmin here by wim leers http://wimleers.com/article/improving-drupals-page-loading-performance

drupalina’s picture

excuse me,

but what exactly are we supposed to do with this .zip file???

I've unzipped it and overwrote all content of Javascript Aggregator module (i can see there is a new .inc file there). But nothing seems to change in terms of performance? Am I missing something?

derjochenmeyer’s picture

it provides a new setting on admin/settings/performance ... i didnt test it myself ... i just had time to look at the code ... make sure you have PHP5 running ...

drupalina’s picture

I do have php5 running
After a while this package broke my sandbox site with a WSOD -- apparently it broke the drigg module that I was runing.

...and there was no extra option in /admin/settings/performance

Was I supposed to put that .inc file in the /includes folder? or keep it in the javasript_aggregator folder by default?

derjochenmeyer’s picture

this function is new... it looks for the inc file in the javascript_aggregator folder... so just leave it there:

/**
 * Perform basic code compression for JavaScript.
 * Helper function
 * RUSLAN
 */
function _drupal_compress_js($script) {
	$jsmin = drupal_get_path('module', 'javascript_aggregator').'/jsmin.inc';

	if(file_exists($jsmin)){
		require_once($jsmin);
		$script = @JSMin::minify($script);
	}
	return $script;
}

then ruslan's version replaces my basic comment removal with a call to that new function _drupal_compress_js()

				if (variable_get('javascript_aggregator_optimize_js', 0)) {
					// Perform some safe JS optimizations.
					$data = _drupal_compress_js($data);
				}

it furthermore just replaces my comment removal setting on the settings page with the JSmin script... i think thats all

antipix’s picture

Nice module, exactly what i need !!! and nice use of jsmin to minify the javascript output !
thanks

d0t101101’s picture

I have to installed and working (everything enabled under administer>performance), but when checking my site with yslow it still grades my site as an F for 'minify JS'. One of the files listed as not be obfuscated/minified is:
http://www.mysite.net/files/js/b1b937a5638374f71604784ea12b234b.js

Any suggestions?

Regards
.

drupalina’s picture

Does this .zip package actually work for anybody?

Any chance of a README.txt file?? or rome guidance as to what to do with this .zip package to get it to work?

thanks

derjochenmeyer’s picture

it should work for anybody with php5 ... just install/enable like a normal module release ...

RobertOak’s picture

Just to let you know I applied this zip from the original module and it looks like it speed up my site load by an entire second from the original Javascript Aggregator, so this looks like an good optimization. Thanks to both of you.

drupalina’s picture

Thanks.
I have a PHP5.
I over-wrote the files inside /javascrip_aggregator folder with whatever is inside this .zip folder (i kept the readme and licence files, just in case I may need them)

Then I ran the update script (as usual in such cases of module changes)

Then I go to my Performance section, and there are no new options.

Did I do everything correctly? Is the JSmin active now??? Did I miss anything?

derjochenmeyer’s picture

There are no "new" options ... but one is replaced and slightly renamed ...

It should read "Optimize JavaScript files with JSMin" thats what you want to activate ...

drupalina’s picture

got it... finally it worked on my live site. (it didn't wok on my localhost).

anf my js aggregations are now half the size

thank you Rusland and derjochenmeyer !

d0t101101’s picture

Hi Drupalina,

And does YSlow now give you an 'A' for 'minified JS'?

Thanks,
.

drupalina’s picture

d0t101101

The short answer is: YSlow is showing no difference.

Yslow gave me an "A" for "minified JS" as soon as I installed the old version of JS aggregator. IT would show an A and then a liitle triangle next to it would show that the aggregated JS file with a long name is not minified.

With this JSmin JS aggregator , it's the same: it shows an "A" for Minify JS, but then also lists the aggregated file as not Minified.

But I think I know the reason why it is doing that: if you go to YSlow >> Tools >> All JS , you will note that even through the spaces have been considerably reduced, these are still some minor spaces left (but that's ok, I guess). I mean, after all, the size of the file as been halved!!!

I can say that for now at least I'm very satisfied with the result. My original JS aggregate files were over a whopping 300kb, and I'm now serving GZipped versions of this JSmin aggregated files which are 34kb (10 times smaller). When it is not GZipped the file is circa 140kb (half of the original). I GZip the aggregated files manually every morning. In a separate issue I asked the maintainers of JS Aggregator module to try to find a solution to automatically create GZipped versions of the JS aggregation file. I believe that TinyMCE's own compressor works in a very similar way to what I had in mind. There is also the JSmart project and this issue http://drupal.org/node/248909

When GZipping of the JSmin JS Aggregation file is is done automatically, that is what I would call a perfection. For now, however, I would call JSmin a very positive step forward.

d0t101101’s picture

Excellent, thanks for the thorough description ;)
.

antipix’s picture

I made some change on the js aggregator to make the js files totally minified (no comments, no break line, etc) and it works perfectly !!!
Thanks to the module author and the patch author ^^

chirale’s picture

It works! I'm using it on my site and I got a -30% file. I make some test trying to gzip the result speculating about the drupalina proposal (Gzip on aggregation/cron) and the result is even better.

chirale’s picture

derjochenmeyer, GNU GPL and "MIT License" (Expath license) are compatible. Free Software Foundation stated that

the plug-ins must be released under the GPL or a GPL-compatible free software license, and that the terms of the GPL must be followed when those plug-ins are distributed

(on GPL FAQ)

I don't know if Drupal has license limitations stronger than FSF, but I think that for FSF it can be done. Maybe contacting the author could clarify this point, even if a "double license" request is not strictly necessary.

RobLoach’s picture

Status: Active » Fixed

I got permission from the author of JSMin.php to add it to the repository.

TinyMCE won't work with the minification, so you have to exclude it by using "tinymce.js" in the exclusion codes.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.