This method can be integrated into the build process, or as part of an application's startup to always create new minified scripts as needed. Scripts are only minified if the minified files don't already exist and are older than the corresponding JavaScript file.
A common usage scenario is to call this static method from Application_Start:
void Application_Start(object sender, EventArgs e) { // *** creates minify scripts if don't exist or are changed // *** NOTE: REQUIRES that IIS/ASP.NET Account has writes to write here! Westwind.Web.Controls.JavaScriptMinifier.MinifyDirectory(Server.MapPath("~/ scripts"), ".min.js", true); }
to always ensure minified files are in sync with corresponding JavaScript files.
public static void MinifyDirectory( string path, string minExtension, bool recursive );
minExtension
The extension for the minified files (ie. .min.js). Include leading dot!
recursive
Determines whether nested directories are also included
When called from ASP.NET this routine REQUIRES that the server account that ASP.NET/IIS AppPool runs under (NETWORK SERVICE by default) has rights to write out the file to the folder specified. Otherwise an exception occurs.