-1

I don't know whether there is a solution to this issue, but I have a large set of Javascript functions bearing long descriptive names, something like:

function getTimeFromTimezoneInMilliseconds(...) { ... };
function computeDifferenceFromUTCInMilliseconds(...) { ... };
...

These long names help explaining what the code does, since some operations are complex and not obvious to understand when reading the code only. It helps maintaining the code too.

I am minimifying this Javascript code, but of course, those names are not minimified.

Is there a refactoring trick in Javascript that would allow minimifiers to pick smaller function names and reduce the code size?

Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
  • Wrap your code in an IIFE to make them non-public. – SLaks Aug 05 '13 at 15:23
  • You are not really adding anything with the word `compute`, that's just obnoxious. `InMilliseconds` is something that could be argued about (unless you have other possible units and it is an overload, but I doubt that) but can definitely be left out from the name itself in my opinion. The first function I don't understand at all because getting time from timezone doesn't make sense. – Esailija Aug 05 '13 at 16:06
  • @SLaks Thanks, if you create a solution, I will approve it. – Jérôme Verstrynge Aug 05 '13 at 16:57

2 Answers2

1

Don't minify yourself! Let the machine do the hard parts.

There are many different options.

  • You can use an online site where you paste your code and you get the minified back (manual).
  • You can automate and use a server-side language to minify your JavaScript.
  • You can use Google CC or Yahoo YUI Compressor to minify and greatly optimize your code.
Halcyon
  • 57,230
  • 10
  • 89
  • 128
  • I am already using HtmlCompressor, which contains the Closure compiler. The solution I was looking for was more how to have Closure compress the function name. I guess an IIFE will do (c.f. SLaks) – Jérôme Verstrynge Aug 05 '13 at 16:56
1

You should wrap your code in an IIFE.

This way, you won't have any public members at all, and the minifier will be able to do whatever it wants.

This has the added advantage of not polluting the global scope.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964