Compress CSS/JavaScript before publish/package

爷,独闯天下 提交于 2019-12-11 10:57:59

问题


I've been reading this post about minifying and compressing static files like CSS/JS within the 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.


回答1:


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.




回答2:


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/



来源:https://stackoverflow.com/questions/5399034/compress-css-javascript-before-publish-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!