[FW]: compress your script and then combine multiple files for faster page Load

Source: Internet
Author: User

The author is Weitong Lin.

With pages include more and more Ajax functionalities,
We may need to include multiple JavaScript files. This may effect the page
Performance.

Here are two utilities that can help us load page faster.

 

1. Compress JavaScript files: 

You can refer to Yui compressor for. Net (http://yuicompressor.codeplex.com/Wiki/View.aspx? Title = home)

It can compress both JavaScript and CSS. Really cool!

 

2. Combine multiple files 

Are you using Ajax-Toolkit 3.5 in your project? If yes,
Please go to "B ".

A. Please get a brief idea of how to combine
Javascript/CSS files by http://www.codeproject.com/KB/aspnet/HttpCombine.aspx.

That's easy to follow the post to import this functionality
To your project.

But it needs to modify ate the JavaScript files reference
By WEB. config which is a little inconvenient.

So for our project, I created a customer control and
Update the scripthandler(compress-and-combine-js-css.rar), then we can add JavaScript reference
Below:

< C0: scriptregistercontrol ID = "Scriptregistercontrol1" Runat = "Server" >
< Scriptitems >
< C0: scriptitem Path = "Script/framework/jquery/jquery-1.2.6.js"   />
< C0: scriptitem Path = "Script/framework/jquery. layout. js"   />
< C0: scriptitem Path = "Script/framework/jquery/UI. Core. js"   />
< C0: scriptitem Path = "Jswebconfig. js"   />
< C0: scriptitem Path = "Script/framework/jquery/query-1.2-stringObject.js"   />
</ Scriptitems >

</C0: scriptregistercontrol> 

Then the script will render as one script:

 

B. if you already include Ajax-Toolkit 3.5 in
Your project, then use the similar functionality that provided
Scriptmanager.


< ASP: scriptmanager ID = "Scriptmanager1" Runat = "Server" >
< Compositescript >
< Scripts >
< ASP: scriptreference Path = "~ /Script/framework/jquery/json2.js"   />
</ Scripts >
</ Compositescript >
</ ASP: scriptmanager >

 

Hope it can benefit for your projects.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.