The technique it's quite simple: trim all white-spaces or other dispensable characters/symbols, remove the comments and other block delimiters, shorten the function/variable names and probably your code will lose some 2/3 of its weight. Of course, we don't want this "new code" on our development environment otherwise the code will become unmaintainable (see the first paragraph). The code will be shorted on its way from the development toward the production environment or even better, at runtime ,while the end-user will load the content from our web server. This process is called minification. This technique is old as the hills, Douglas Crockford did it more than a decade before. His C++ source code was made available and it's only 307 lines long. Looking at his code while writing this article I just realize that his code is just a parser specialized on removing the unnecessary white-spaces and/or the code comments. Actually this is the way that such a tool should be designed: build a code parser that understands the source language it deals with and that's it. I did it before by writing a parser for Assembly (an Assembly and a SQL editor plug-in for Eclipse) so I already knew that this was the right way of doing it. But I wanted to try achieving this only with regular expressions (aka regex) and such the YAYUI had borned.
What is YAYUI
You can test/workout the application at http://yayui.mynixworld.info. I just realized that this minifier (which has also code obfuscation capabilities) is around 300 lines of code, too. Moreover, comparing with other similar tools that are available online I saw that YAYUI produces more/less the same output so that's not bad!
Below I embed some info I made available at YAYUI web page:
Now, if you think that this article was interesting don't forget to rate it. It shows me that you care and thus I will continue write about these things.
Latest posts by Eugen Mihailescu (see all)
- Gentoo AMD Ryzen stabilizator - April 29, 2018
- Symfony Compile Error Failed opening required Proxies - January 22, 2018
- Symfony authentication redirect after each request - January 22, 2018