Microsoft Ajax Minifier Quick Start
2012-07-02 17:31
344 查看
Using the Microsoft Ajax Minifier from the Command Line
After you install the Microsoft Ajax Minifier, you can use the tool from the command line. Open the Microsoft Ajax Minifier CommandPrompt from the Microsoft Ajax Minifier program group. Next, enter the name of an input file and the name of an output file like this:
ajaxmin test.js -o test.min.js
The Microsoft Ajax Minifier will report how much it was able to minify the file (for example, 43%).
You also can use the Microsoft Ajax Minifier to minify Cascading Style Sheet files. You use the same syntax:
ajaxmin test.css -o test.min.css
Using the Microsoft Ajax Minifier as a Build Task
You can integrate the Microsoft Ajax Minifier into your Visual Studio Build process. Every time you perform a build in a Visual StudioASP.NET project, you can minify all of your JavaScript and Cascading Style Sheet files automatically.
You can use the Ajax Minifier with both ASP.NET Web Forms and ASP.NET MVC Web Application Projects (WAPs). However, you cannot use
the minifier with ASP.NET Web Forms Websites.
Follow these steps:
1. Within Visual Studio, select the menu option Tools,
Options, Projects and Solutions. Check the checkbox labeled Always
show solution
2. Within Visual Studio, right-click your project in the Solution Explorer window and select the menu option Unload
Project
3. Select the menu option Edit project
name
4. Add the following code immediately above the closing <project> tag:
view plaincopy
to clipboardprint?
<Import Project="$(MSBuildExtensionsPath)\Microsoft\MicrosoftAjax\ajaxmin.tasks" />
<Target Name="AfterBuild">
<ItemGroup>
<JS Include="**\*.js" Exclude="**\*.min.js;Scripts\*.js" />
</ItemGroup>
<ItemGroup>
<CSS Include="**\*.css" Exclude="**\*.min.css" />
</ItemGroup>
<AjaxMin
JsSourceFiles="@(JS)" JsSourceExtensionPattern="\.js$" JsTargetExtension=".min.js"
CssSourceFiles="@(CSS)" CssSourceExtensionPattern="\.css$" CssTargetExtension=".min.css" />
</Target>
This code imports a custom MSBuild task named ajaxmin. The ajaxmin task is used to minify all of the JavaScript and CSS files contained
in the project automatically. All JavaScript files are renamed with the extension .min.js and all CSS files are renamed with the extension .min.css.
5. Right-click your project in the Solution Explorer window and select the menu option Reload
Project
After you complete these steps, all of the CSS and JavaScript files in your project will be minified whenever you do a build automatically.
The minified files will not appear
in the Solution Explorer window. To see the minified files, you must select the menu option Project, Show All Files.
Using the Microsoft Ajax Minifier with Source Control
The Microsoft Ajax Minifier generates the minified JavaScript and CSS files as the output of the build process. For this reason, werecommend that you handle the minified files in exactly the same way as you would handle the assemblies generated by the build process. In particular, we recommend that you do not include the minified files in your Visual Studio project and that you do not
check the minified files into source control.
If you include the minified files in your project, and you use source control, then you will encounter problems. When files are checked
out of source control, they are checked out with their read-only attributes set. If you attempt to do a build, the Microsoft Ajax Minifier will generate an error when it attempts to write to a read-only file.
相关文章推荐
- Microsoft Ajax Minifier 介绍
- Announcing Microsoft Ajax Library (Preview 6) and the Microsoft Ajax Minifier
- Ajax.Net Professional——A quick guide how to start(AjaxPro开始向导)
- 利用Microsoft Ajax Minifier在服务器端对静态资源进行自动化压缩
- js压缩工具 : Microsoft Ajax Minifier
- Microsoft Ajax Minifier 使用综合
- Quick start for Microsoft MVC3 with Razor View Engine
- Microsoft Ajax Minifier 压缩javascript
- Ajax 对象 xmlhttp --dojo Quick Start/dojo入门手册2
- Microsoft Ajax Minifier用法
- 将Microsoft Ajax Minifier集成到VS2013对JS、CSS进行编译时压缩
- 使用Microsoft Ajax Minifier减小JavaScript文件大小
- 将Microsoft Ajax Minifier集成到VS2010对JS,CSS进行编译时压缩
- Microsoft Ajax Minifier 4.0
- [前端优化]使用Microsoft Ajax Minifier对资源文件进行压缩优化
- Microsoft Ajax Minifier 压缩javascript的方法
- 用Microsoft Ajax Minifier技术高效率压缩Js文件
- 使用Microsoft Ajax Minifier减小JavaScript文件大小的方法
- 【翻译】Microsoft Ajax Minifier 快速使用指南(与VS集成使用) 编译后直接压缩项目的JS或CSS文件