We happened to maintain several files for JS and CSS files and ensured that we used a number of files with some nomenclature like debug.01.file1.js / debug.01.file1.css
Reason, being we needed multiple files for modularization and also as we were using several third party plug-ins.
Another reason, was that ordering of processing the files does matter in some cases ex: jquerymobile js files needs to be preceded by jquery script files.
The final consolidated file will have a name of projectname.js / projectname.css
We used YuiCompressor for minification of js and css files.
Steps to setup:
Yuicompressor
downloadable : http://yui.zenfs.com/releases/yuicompressor/yuicompressor-2.4.7.zip
Extract
the zip folder to c:\ i.e.
c:\yuicompressor-2.4.7
More
Info : http://developer.yahoo.com/yui/compressor/
Java
runtime download : http://www.java.com/en/download/index.jsp
Setting
Environment Variables to Java and Yuicompressor binaries.
Start
> My Computer > Properties > Advanced System Settings > Environment
Variable >
Append
the below string to the PATH variable.
;C:\Program
Files (x86)\Java\jre6\bin
type
"$(ProjectDir)scripts\debug.*.js" | java -jar
"C:\yuicompressor-2.4.7\build\yuicompressor-2.4.7.jar" --type js -o
"$(ProjectDir)scripts\okig.mobile.js"
type
"$(ProjectDir)styles\debug.*.css" | java -jar
"C:\yuicompressor-2.4.7\build\yuicompressor-2.4.7.jar" --type css -o
"$(ProjectDir)styles\okig.mobile.css"
Set the Post build event to run the following script. This will ensure that minification is done only in case of release mode. Version is done for both debug & release mode.
if $(ConfigurationName) == Release (
echo 'Minifying the JS and CSS'
type "$(ProjectDir)scripts\debug.*.js" | java -jar "C:\yuicompressor-2.4.7\build\yuicompressor-2.4.7.jar" --type js -o "$(ProjectDir)scripts\okig.mobile.js"
type "$(ProjectDir)styles\debug.*.css" | java -jar "C:\yuicompressor-2.4.7\build\yuicompressor-2.4.7.jar" --type css -o "$(ProjectDir)styles\okig.mobile.css"
)
Might consider using the YUI Compressor for .net (http://yuicompressor.codeplex.com/) or the MS ajax minifier (http://ajaxmin.codeplex.com/) to avoid the dependency on the java run time since both provide a command line entry point. Both are available on nuget.
ReplyDeleteAlso, if you can afford turning off the sharepoint 2010 output caching, consider using http://RequestReduce.com which will automatically find, minify and bundle all scripts and css. It can also automatically sprite the css background images.
Thanks Matt. I agree with you on the JRE dependency for YuiCompressor. I had seen them but since, they did not have enough rating/downloads, I did'nt want to take a chance.
ReplyDeleteI had not come across the RequestReduce project. May be will give it a shot.