最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Minified JS causes JS to not work - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question asked Aug 26, 2010 at 20:23 dzmdzm 23.5k50 gold badges152 silver badges229 bronze badges 5
  • What error are you getting, also are you using eval()? – Nick Craver Commented Aug 26, 2010 at 20:26
  • The reason: the minifying changes the code. It should preserve the functionality but apparently it doesn't. We can't say much else without your code I am afraid (aside from guessing like Nick does) – Jasper Commented Aug 26, 2010 at 20:28
  • You'll also want to check to make sure you didn't miss any semicolons at the end of a statement - missing those can often cause minifying to go all wrong. I agree with Jasper, without seeing the code it's hard to know for sure, using jslint, as S.Jones suggested is a good way to find missing semicolons and other potential problems. Can you share the code? – John Commented Aug 26, 2010 at 20:50
  • Which minifier are you using? – Cristian Sanchez Commented Aug 26, 2010 at 21:01
  • Could we get a sample of one of these files that does not work when minified? – austincheney Commented Mar 18, 2012 at 4:43
Add a comment  | 

1 Answer 1

Reset to default 17

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"

发布评论

评论列表(0)

  1. 暂无评论