Reputation: 1481
I have a complex web app on an embedded system and soon it will be going through testing. Currently all files are in their source form for debugging. I will absolutely need to minify all JS and CSS and I am wondering if there is any chance that something could go wrong. Is it better to test the code minified or in a source state?
Thanks.
Upvotes: 4
Views: 2109
Reputation: 48247
If a cosmic ray were to penetrate your build server's case and hit the memory while the minification was happening, it could ruin everything. The chances of that are very small, though.
Another step in your build will always introduce complexity and have a potential for errors, especially when it modifies a file. Your testing will discover that, since you should always test what you plan to deploy to production. If you deploy the minified code, you test the minified code.
Minification is so widely used that most of the tools are pretty mature and robust, with excellent accuracy at detecting what is in-use and what is not. They are very good at not removing code that is used in an unusual way.
However, it is possible for the minifier to decide something isn't being used and be incorrect. In that case, your unit and/or integration testing should fail and you'll be able to change the code or tell the minifier to keep the section that was missing.
Those fixes are pretty quick and usually obvious, so the advantages of having a few small files (instead of many larger files) will almost always outweigh them. Since minifiers rename code significantly or remove it entirely, even simple smoke testing of your app is often enough to expose any errors.
As an example, Google's closure compiler has a tutorial on handling global and external variables, exports, and unused code you need to keep.
Upvotes: 6
Reputation: 700212
Generally there is no functional difference between the original code and the minified code. The minifying process should only do safe changes to the code when minifying it.
However, I always say that any system that is complex enough to be really useful, also has bugs. Even if it's very unlikely that you happen to stumble on a bug in the minifying code, it's still possible.
I would recommend that you test the code minified. You could perhaps run the first tests with unminifed code, as it's a lot easier to debug the unminified code.
Upvotes: 1