Question

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?

Était-ce utile?

La solution

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.

Autres conseils

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.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top