How to minify javascript and css file in Windows

Leon Yap
1 min readJun 18, 2019

--

Minifying js and css file has been a standard practice to reduce the webpage size.

Various tools are created to tackle the problem, especially on Mac OS X that includes batch processing capabilities.

However, it is a pain to do so in Windows without installing 3rd party extension into IDE.

This motivate me to write a simple script that can batch processing the js and easy to use.

This is a batch script that minify js and css files using AjaxMin

The script will scan recursively from current folder to all its sub-folder.

It will save the minified file with .min.js or .min.css

This batch script required AjaxMin to run, install AjaxMin into its default folder

C:\Program Files (x86)\Microsoft\Microsoft Ajax Minifier

@ECHO off
set PATH=”C:\Program Files (x86)\Microsoft\Microsoft Ajax Minifier\”;%PATH%
setlocal enabledelayedexpansion
for /f %%f in (‘dir /b /s^|findstr /r “.*\.js$ .*\.css$”’) do (
set “N=%%f”
if “!N:.min%%~xf=!”==”!N!” (
@ajaxmin -clobber %%f -o %%~npf.min%%~xf
)
)
pause

save the script as .bat file
copy it to your /js folder and run it.

Feel free to copy and modify.

Originally published at http://yklun.blogspot.com.

Sign up to discover human stories that deepen your understanding of the world.

--

--

Leon Yap
Leon Yap

Written by Leon Yap

Caffeinated programmer at work.

Responses (2)

Write a response