AjaxMin4Setup.msi 压缩CSS和JS文件提高网页的加载速度
01.<Import Project="$(MSBuildExtensionsPath)\Microsoft\MicrosoftAjax\ajaxmin.tasks" /> 02.<Target Name="AfterBuild"> 03.<ItemGroup> 04. <JS Include="**\*.js" Exclude="**\*.min.js;Scripts\*.js" /> 05.</ItemGroup> 06.<ItemGroup> 07. <CSS Include="**\*.css" Exclude="**\*.min.css" /> 08.</ItemGroup> 09.<AjaxMin 10. JsSourceFiles="@(JS)" JsSourceExtensionPattern="\.js$" JsTargetExtension=".min.js" 11. CssSourceFiles="@(CSS)" CssSourceExtensionPattern="\.css$" CssTargetExtension=".min.css" /> 12.</Target>
Microsoft Ajax Minifier Quick Start
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 Command Prompt 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 Studio ASP.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:
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:01.<Import Project="$(MSBuildExtensionsPath)\Microsoft\MicrosoftAjax\ajaxmin.tasks" /> 02.<Target Name="AfterBuild"> 03.<ItemGroup> 04. <JS Include="**\*.js" Exclude="**\*.min.js;Scripts\*.js" /> 05.</ItemGroup> 06.<ItemGroup> 07. <CSS Include="**\*.css" Exclude="**\*.min.css" /> 08.</ItemGroup> 09.<AjaxMin 10. JsSourceFiles="@(JS)" JsSourceExtensionPattern="\.js$" JsTargetExtension=".min.js" 11. CssSourceFiles="@(CSS)" CssSourceExtensionPattern="\.css$" CssTargetExtension=".min.css" /> 12.</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, we recommend 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.
资料出处:http://HdhCmsTestasp.net/ajaxLibrary/AjaxMinQuickStart.ashx
作者: Leo_wl
出处: http://HdhCmsTestcnblogs测试数据/Leo_wl/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
版权信息查看更多关于AjaxMin4Setup.msi 压缩CSS和JS文件提高网页的加载速度的详细内容...