View Full Version : compress js

10-30-2015, 09:11 AM
I can't find how people make js,file in to small script.
I have problem with big js,file,..because is to long for my HTML,and if I put few more,it make block for my HTML.
Someone can help me explain what need to do for make small script js.file.
For exaple like that:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>


10-30-2015, 11:33 AM
Are you talking about minification? Where all white space / new lines are removed to compress the script and therefore file size?

If so, do a search for "minify JS" and you'll find lots of online tools to do the job.

02-04-2016, 10:17 AM
I'm trying to minify js to reduce file size but after minifying I find that my site doesn't run properly. Does this happen to anyone else?

04-28-2016, 03:15 AM
Yes. In order to minify, depending upon the method used, the script code must increasingly adhere to standards, otherwise, conventions that allow for omissions at the end of lines will no longer be understood, and/or comments (if not stripped) can become problematical. For example, one can go:

var bob = "you're uncle"
var ted = "alice"

But without proper strict terminus, that cannot become:

var bob = "you're uncle"var ted = "alice"

But if originally it was strict:

var bob = "you're uncle";
var ted = "alice";

It then can become:

var bob = "you're uncle";var ted = "alice";

There are so many conventions like these that are loosely OK with line breaks, that will break a script if those line breaks are removed without adding strict notations of one sort or another that - well I think you get the idea.

Basically strict javascript code is much more easily/successfully compressed than more loose/haphazardly written code.

jslint is a good if sometimes frustrating tool to use to ready your javascript code for successful compression:


Even so (making the code compliant with such a tool), some certain techniques can still cause problems once code is compressed. For those, individual investigation is required.

That said, javascript is ordinarily not all that big. You will have far greater savings in most cases via compressing the images a page uses.