Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minified JS causes JS to not work

I'm using carabiner for CodeIgniter which can minify all the javascript files it loads. Well, I have about 10 files that work fine, then when minified, they don't... I'm not sure exactly what doesn't work, there are no errors, just certain features that don't work. Is there any particular reason why minifying JavaScript would cause it to not work?

like image 519
dzm Avatar asked Aug 26 '10 20:08

dzm


People also ask

Should JavaScript be minified?

To regain space and improve your page load speed, you must minify the JavaScript code. The minified version of JavaScript code can reduce the file size by as much as 30–90%. Consequently, JavaScript minification has become a familiar ritual for all developers.

Why are JS files minified?

The main purpose of JavaScript minification is to speed up the downloading or transfer of the JavaScript code from the server hosting the website's JavaScript. The reason that minification makes downloads go faster is because it reduces the amount of data (in the minified JavaScript file) that needs to be downloaded.

How do you check if a JS file is minified?

Maybe you can try by checking how long the lines are, and how many spaces are used. Minified/packed JS typically has almost no spaces (typically in strings) and very long lines.

How do I debug a JavaScript minified file?

Open any web site. Open developer tools in chrome by pressing F12 /Ctrl + Shift + I/ right-click anywhere inside the web page and select Inspect/Inspect Element which will be mostly the last option. Go to Sources tab in developer tools and open any minified JS which you want to debug as shown in the image.


1 Answers

You may want to try running JSLint on your Javascript code before you try to minimize it. JSLint might highlight some issues, which could allow you to minimize your code without error.

Or you may want to try another 'minification' tool.

Here are two articles I've found on 'A List Apart,' that may interest you, looking at the YUI Compressor.

"Better JavaScript Minification"
"JavaScript Minification Part II"

like image 140
S.Jones Avatar answered Oct 12 '22 23:10

S.Jones