Minify JS and CSS files in batch with drag-and-drop

CSS, Javascript, Performance 5 responses so far

Minification of JavaScript and CSS files is one of the best practices to keep your site’s load time to the minimum, especially important for the first time visitors. In organized projects, minification is part of the deployment process and it is integrated into that very smoothly using appropriate tools.

If you wish to minify the JavaScript and CSS files without pre-deployment scripts minifying the .js and .css files, your best bet is to use a command-line tool like JSMin (JavaScript files only) or YUI Compressor (supports JavaScript and CSS files, both).

To make this process even smoother, as easy as drag-and-drop, we have provided a batch file (for Windows users) which can minify multiple files in a single go. To minify, you just need to drag-and-drop any JS or CSS files into the batch file and with the help of YUI compressor, the mininfied version of the file will be created in the same folder as that of the original file.

You can even right click on a JS or CSS file and use the “Open With” option and set it to execute with the provided batch file.


  • Java needs to be installed on your system to execute YUI Compressor.

How it works:

  • You can drag-and-drop multiple files over the batch file (you can even drag-and-drop .js and .css files together)
  • The drag-and-dropped files are processed one-by-one
  • YUI Compressor (which is stored in the same folder as that of the batch file) identifies the file type (.js or .css) and minifies it accordingly
  • The new file is created in the original file’s folder and ‘.min’ is added before the extension of the original file name.
  • There is no warning shown if the target “.min” file already exists. It will simply be overwritten.

Source code:

@if [%1] == [] goto argsmissing

@if [%1] == [] goto end

@echo %1

@set opfile=%~n1.min%~x1
@cd "%~d1%~p1"

@echo %opfile%

@java -jar "%~d0%~p0yuicompressor-2.4.7.jar" --nomunge --disable-optimizations %1 -o "%opfile%"

@REM - Shift the arguments (do not alter first argument) and examine %1 again
@shift /1
@goto again

@echo Argument(s) missing
@echo usage: batFile.bat file1.js file2.css ...

The following two tabs change content below.
  • hi, download link is corrupted…. can you check pls.

  • @Shah Alom: Download Link has been fixed now

  • pranav

    this script currepted not working..check it..any video tutorial for this

  • shuvaranjan saha

    Bogas file

  • kellyStephens

    I really like the tool and ease of use for minifying my JavaScript files on they use UglifyJS so you also get obfuscation and you can even combine as many files as you like and it will make them a single file and compress JS. It is a regularly updated tool as UglyfyJS gets updated.