By default my scripts have no indentation once downloaded via the site, I intend to put an option that allows to download the original indented scripts in order to let the user choose a more readable code, but by default the code will always be minified.
Minification is code that is relieved of unnecessary constraints to its proper functioning, increasing the weight of a file. The beauty of a code takes up space, a code is not just made to look good, but to provide a service that works, better performance and better SEO when it applies to the web.
Not minifying a code can make sense if several people are working on it because it allows this team to see clearly and to have a better organization.
Here, you have to realize that the code is converted only at the time of downloading. And this has never been a problem for me in terms of the maintainability of the source code and the numerous updates I publish every week.
To give an example of comparison, the weight of my finished gamemode is more optimized than a single lambda addon. Thanks to the complete minification of the source code. Yet it is extremely complete and also contains a unique administration system within its source code, 540 different objects all useful. And 0 addon.
7 seconds and loading time despite the 300 npcs on the map on loaded, the thousands of drivable vehicles and the objects present (which I advise not to do, but the optimization of the totality of my entities allows me to keep a fluid server)
In web, a not minified code is in my opinion a not finished code.
Gmod servers often suffer from loading when there are a lot of scripts and a lot of addons, users take a long time to reach a server and sometimes get discouraged before the end of the loading. Reducing this time could avoid that they leave before the end of the loading, this method applied to all your scripts is not to be neglected.
In programming, minification means to reduce the size of the code to reduce the size of a program to download from a server and thus reduce the network congestion, on Gmod the size of a Lua file on the client side if it is minified will be faster to download. This is one of the many existing optimization rules.
For this we remove all unnecessary comments and characters. These deletions will not interfere with the proper functioning of the application. The download module will also replace the names of the internal variables local to the application to reduce them to one or two characters in an automated way. It is also possible to use some compact writings specific to the languages (color in hexadecimal, shortcuts...)
This process is very much used in web programming and especially very recommended.
2. Example of minified code
Exemple 1: Unminified code
local function my_supermegahyper_test ( Player , Argument , NUMBER )
local firstnumber = NUMBER ;
return firstnumber * 2;
concommand.Add( "give_me_double" , my_supermegahyper_test )
Example 2: Minified code
local function test(a,b,c)return c*2 end
3. Frequently asked questions
Question: What is minification? Answer: Minification is an optimization of the file size by removing unnecessary characters without impacting the proper functioning of the script. It also removes unnecessary spaces and indentation.
Question: What is indentation? Answer: Indentation consists of adding one or more tabs at the beginning of certain lines in a program to make it more readable.
Question: Does removing the indentation change anything? Answer: Well, no.
Question: Is removing the indentation a maintenance issue? Answer: No, those who have experienced my support always appreciate my responsiveness. My source code on my side to work is not the minified version. And at worst when there is an error on line 2 of the init.lua file. Well, you have to expect that there is no need to search more.
Question: Where does minification come from? Answer: Minification is a form of web optimization recommended by Google to reduce the loading time of sites to the maximum and to the bare minimum necessary to function.
Question: You talk about downloading less heavy files but there are variables that exist in your addons that seem not to be used in the code, why? Answer: This could be the case with the scripts from 2015 to 2017 when I was on Gmodstore. A lot spread by the leak of my scripts. Today if a variable seems useless it's because you are making a mistake to consider that they can't work in combination with other of my products that will need its variables to work well.
Question: Why did you make this choice? Answer: I made this choice by default to reduce the size of the files. Smaller files take less space in the cache usually stored in memory, and downloaded by the client at its connection, so a choice that impacts the loading time for Lua files because less large Lua files to download for your users, choice that I also apply here on this site and that pays off in performance. We all know that a user will leave a page more easily if its loading time is too long. Test this site on Google speed for example in comparison with another site (without targeting anyone) which is a reference for you, you will understand what I am talking about.
4. How to reduce the loading time of users when they join my Gmod server?
How to reduce the loading time of my users on my Gmod / DarkRP server or other gamemode?
- Reduce the number of workshop addons to what is strictly necessary for your project, do not have unnecessary and superfluous content downloaded, the longest loading time is there, the workshop addons.
- Install scripts downloaded from sources offering a minified version![/u] Here we will reduce the size of the downloaded Lua files.
- Don't overload your maps with badly optimized entities.
Minification is not the ultimate and micracle method to optimize your server if you are running with 200 workshop addons, it is only a step.
Applying minification on a whole program gives a result that is not negligible especially if it is downloaded during the connection of each user.
This method is used to reduce the download time in many languages.