I was debugging the ‘woo-variation-gallery’ plugin for WordPress. I found that under ‘asset->js’ folder, for every XXX.js file there is a XXX.min.js file present. For example :
1. admin.js ---- admin.min.js 2. frontend.js ----- frontend.min.js 3. so on....
I would like to understand the significance of xxx.min.js file ? What’s the purpose of these *.min.js files ? Why corresponding to every .js file in the folder, there is a .min.js file present ?
Thanks.
Advertisement
Answer
It’s a little disappointing that you didn’t Google ‘min.js’ before raising this on Stackoverflow, but perhaps you’re getting started at this so welcome!
As you’ll see from the first hit, a min.js file is a javascript file that has undergone minification which reduces the size and simplifies the code as much as possible without changing any of its behaviour.
This typically makes it unreadable by replacing meaningful names with ultra-short ones, substituting unconventional but performant implementations and eliminating whitespace and unnecessary separators.
A more nuanced but related question is why do they have the non-minified versions there too, given presumably only the min.js files are actually loaded and run. I guess that’s for the potential of debugging the running code using a sourcemap where you can be actually running the minified version but stepping line-by-line through the human-friendly version.
It’s always worth investing a little bit of time researching a question before raising it here. You normally learn a lot while proving you did your research, and often you find the answer yourself and don’t need to raise it at all.