Summary

Combine script is general function for optimize speed of loading web page by reducing amount of file to be downloaded from web server. Currently, it supports both JavaScript and Css files. For Css file, all url-based value will be replaced with correct value if combined Css is not the same directory with original file.

If there are some changed files in script files, combined script will be regenerated. But I use add or remove some script file to combine script method you must remove combined file from your application.

Step

1. Add reference to Microsoft AJAX Minifier 4.0

image

You can get latest version of Microsoft Ajax Minifier by clicking the following link. But If version of AjaxMin or any other 3rd party assemblies is changed, you must re-complies for generating Higgs assembly for the new version changed assembly.

http://ajaxmin.codeplex.com/

2. Create View for testing

@using Higgs.Web.Helpers
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>Basic - Combine Script</title>
    @(Html.CombinedFiles
    (
        "~/Scripts/common.js",
        "~/Scripts/jquery-1.4.4.js",
        "~/Scripts/jquery-ui.js"
    ))
    <script type="text/javascript">
        $(function () {
            $('body').append('Hello World! from jQuery.');
        });
    </script>
</head>
<body></body>
</html>

3. Set debug = false in web.config file

image

4. View Result

As you see, all script files are combined into only one file that name common.js that located in Scripts directory.

image

image

If you change debug to true, you will see something like this.

image

Moreover, you can use static compression feature in IIS 7 by adding the following setting to your web.config file.

<configuration>
  <system.webServer>
    <httpCompression staticCompressionDisableCpuUsage="true">
      <staticTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
      </staticTypes>
    </httpCompression>
  </system.webServer>
</configuration>

Download: Basic - Combine Script.7z

PS. you can see how to create project and add reference at Basic – Hello World.

Last edited Jan 21, 2011 at 8:53 AM by SoulMaster, version 4

Comments

No comments yet.