Compress CSS/JavaScript before publish/package
I've been reading this post about minifying and compressing static files like CSS/JS within the 开发者_JAVA百科publish/package event in VS2010.
I wonder if it also is possible to combine the files to one CSS file and one JS file? And how that can be done in this process.
As far as minifying and compressing your CSS and JS files - that shouldn't be any issue.
However - when it comes to actually combining all of your related files (CSS & JS) into single files, you will need to be careful to avoid any naming conflicts that can occur.
(This is especially important if you are using some already minified JS files - as variables like a,b,c
etc. will be used often.)
The YUI Compresser can handle both the compression of CSS and JavaScript files.
Hope this helps.
Publish time merging is good idea but sometimes say page "A" needs 'a.js' and 'b.js' whereas page "B" needs 'a.js' and 'c.js' and there can many such dynamic combinations. Doing this check at build time and then grouping is sometimes very hectic.
What if grouping happens on the fly for required resources and with one HTTP request like this...
<script language="JavaScript" src="/appContext/js/a,./subdir/b.js"></script>
WebUtilities library (for J2EE) does exactly same and helps with many other front end optimizations.
- Minimizing HTTP requests
- Minifying JS,CSS files
- Minifying inline JS, CSS snipped (custom tag)
- Leveraging browser caching (Expires, Cache-Control)
- Server side caching (until resource changes)
- Early setting charset etc.
Here is the link. Have look in case you find it useful.
http://code.google.com/p/webutilities/
精彩评论