ArticleDirectory
- When the project is to be released, because JavaScript and CSS Code adopts a standard form in the Development era, such as annotations and injection, the size of these files is relatively large, to reduce network traffic and increase the download speed of webpages, JavaScript and CSS should be reduced and the size of these files should be compressed during Publishing. Ajax minifier is such a tool.
When the project is to be released Code The standard format is adopted, such as comments and injection. In this way, these files are large in size. In order to reduce network traffic and increase the download speed of webpages, generally, JavaScript and CSS files need to be reduced during release to compress the size of these files. Ajax minifier is such a tool.
Ajax minifier
Http://aspnet.codeplex.com/releases/view/40584
By default, it is installed in c: \ Program Files \ Microsoft \ microsoft Ajax minifier 4 and includes ajaxmin.exe ajaxmin. dll and msbuild-related content.
After you start ajaxmincommandprompt.batdirectly, you can use ajaxmin.exe in any directory.
The detailed parameter description is included in the document ajaxmin.doc [available on the Website] In the code downloaded from the ajaxmin.codeplex.comsite.
Compressed command line format
The command line file ajaxmin.exe can be compressed by CSS and Js.
Ajaxmin inputfile.css-out outputfile.css
Ajaxmin inputfile. js-out outputfile. js
Project Integration in
Open the project file *. csproj in XML format, and add
< Import Project = "$ (Msbuildextensionspath) \ Microsoft \ microsoftajax \ ajaxmin. Tasks" /> < Target Name = "Afterbuild" > < Itemgroup > < JS Include = "** \ *. Js" Exclude = "** \ *. Min. js ;" /> </ Itemgroup > < Itemgroup > < CSS Include ="** \ *. CSS" Exclude = "** \ * .Min.css" /> </ Itemgroup > < Message Text = "======= Ajaxmin begin ========" /> < Ajaxmin Jssourcefiles ="@ (JS )" Jssourceextensionpattern = "\. Js $" Jstargetextension = ". Min. js"
Jscollapsetoliteral="True" Jscombineduplicateliterals="True" Jslocalrenaming="Crunchall" Jsmacsafariquirks="True"
Jsremoveunneededcode = "True" Jsstripdebugstatements = "True" Jsevaltreatment = "Ignore" Jsinlinesafestrings = "True" /> < Ajaxmin Csssourcefiles = "@ (CSS )" Csssourceextensionpattern = "\. CSS $" Csstargetextension = ".Min.css" /> < Message Text = "======= Ajaxmin done! ========" /> </ Target >
When the project is compiled, all *. CSS and *. js files under the project are automatically renamed to * .min.css *. Min. js.
The ultimate goal is to use min.css and min. js. If the page file is not modified, you can also use Batch Processing
Ajaxmin. bat
@ Echo off
Setlocal enabledelayedexpansion
For/R. % F in (*. Min. M. JS) Do (
Set src = % F
Set DST =! SRC:. Min. M. js =. JS!
Echo! SRC! ! DST!
Copy/y! SRC! ! DST!
)
[Do not run this command in the Development Directory. Otherwise, the developed JS files will be overwritten and run in the deployed directory.]
Standardized Inspection
Like other languages, you can use a tool to check JavaScript code compliance.
Jslint http://www.crockford.com/jslint available online
You can also use ajaxmin
Ajaxmin.exe-analyze-Warn: 4 demo. js
You can also use it in vs. The specific configuration is as follows: [vs Tools menu, add external tools]
Ajaxmin-analyse
C: \ Program Files \ Microsoft \ microsoft Ajax minifier 4 \ ajaxmin.exe
-Analyze-Warn: 4 "$ (itemfilename) $ (itemext )"
$ (Itemdir)
In the project, you only need to select a JS or CSS file for analysis. The output window displays the number of lines with warnings.
Restore
Occasionally, you can use this tool to restore a compressed JS file or analyze the compressed JS file. This allows you to perform better analysis after standardization due to the neat format.
The command is as follows:
Ajaxmin.exe-pretty demo. Min. js-clobber-O demo. js
Others
For JavaScript, there are many other tools for checking and compressing CSS code standards and restoring the network. ajaxmin can be integrated with msbuild and vs for ease of use. The following references:
Http://www.crockford.com/javascript/jsmin.html
Http://www.cnblogs.com/lzhdim/archive/2009/04/26/1443452.html