More tips for #64: Minify

18 views
Skip to first unread message

tomByrer

unread,
Jul 3, 2014, 3:22:05 AM7/3/14
to js-drip-d...@googlegroups.com
ref: http://us6.campaign-archive1.com/?u=2cc20705b76fa66ab84a6634f&id=ca35797c3a&e=d473311058
Thanks for reminding folks to shrink their deployed code!  I find many in production websites wasting bandwidth, HD space, & maybe even to-glass rendering speed since they didn't take the extra step.
Here are a few extra tips:

* Best to include at least the project name, copyright holder, & licence in a top-line comment.  Often legally these need to be included in the files, & will save frustration later when you try to back-source your code.  And never rely on filenames.  If you need a starting point: https://github.com/tomByrer/web-engeneering-notes/blob/master/banner-tips.md

* Online minifiers are handy: http://skalman.github.io/UglifyJS-online/

* You can simply remove whitespace & comments if you think you need to troubleshoot live code, & can't use sourcemaps: http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/

* Minified code might run faster: http://jsperf.com/minified-vs-crushed/2

* If using third-party JS, there may be an already minified (& hopefully tested) code in the repo, or in a CDN like cdnjs or jsDelivr: http://www.jsdelivr.com/

cheers

Joshua Clanton

unread,
Jul 3, 2014, 6:24:33 PM7/3/14
to js-drip-d...@googlegroups.com
Thanks for the added suggestions, Tom!

Josh Clanton

PAEz

unread,
Sep 13, 2014, 12:33:46 PM9/13/14
to js-drip-d...@googlegroups.com
One thought which could be totally wrong ;).....

* Minified code might run faster: http://jsperf.com/minified-vs-crushed/2

... I dont think your testing the execution speed of the try block at the end so much as the "compilation" speed.
I know js is a scripting language but Im pretty sure its got to atleast read the code in first and convert it to something other than straight text and looks for optimizations.
Like I said at the top I could be totally wrong.
The reason I think this and pointing it out is Ive done some tests before (wish I knew where they are;)) and noticed that minified code can run SLOWER than none minified code.
Minifiers can alter your code to use versions of the same thing that take up less text.  These versions arent always as fast as what you wrote.
It was Uglifier (love that code) that I tested against.
I ended up using the compressor on this page....
...because of this once.  Smaller delivery, but didnt change my code.
Reply all
Reply to author
Forward
0 new messages