Web assets represent the JavaScript and CSS files which you are using
in your ASP.NET MVC application.
Telerik Extensions for ASP.NET MVC helps you manage your web assets easily by providing the following features:
Combination
Combining web assets allows you to decrease the total number of requests made to
the web server, in order to improve the page loading time.
Important |
|---|
|
Combined scripts are served by
the WebAssetHttpHandler, so it must
be registered in the web.config of your ASP.NET MVC
application.
|
Grouping
Arranging web assets in groups will combine related assets in a single request. This
is beneficial if you have web assets required by all pages, and some other assets required by a specific page.
The common JavaScript files (such as jQuery) are served in all pages and can be groupped together. Page-specific
JavaScript files can be also groupped together (but not with the site-specific ones).
Consider the following example:
Standalone JavaScript files
| http://example.com/list | http://example.com/view/3 | http://example.com/edit/3 |
|---|
- jquery-1.4.2.js
- jquery-ui-1.7.2.custom.js
- jquery.template.js
- jquery.pagination.js
- Utility.js
- Search.js
- List.js
| - jquery-1.4.2.js
- jquery-ui-1.7.2.custom.js
- jquery.template.js
- jquery.pagination.js
- Utility.js
- View.js
| - jquery-1.4.2.js
- jquery-ui-1.7.2.custom.js
- jquery.validate.js
- jquery.form.js
- jqery.watermark.js
- Utility.js
- Edit.js
|
We can arrange those scripts in the following groups:
- jQueryBase
- jquery-1.4.2.js
- jquery-ui 1.7.2.custom.js
- ListView
- jquery.template.js
- jquery.pagination.js
- Form
- jquery.validate.js
- jquery.form.js
- jquery.watermark.js
- ListLocal
- Utility.js
- Search.js
- List.js
- ViewLocal
- EditLocal
Now the scripts will be output like this:
Groupped and combined JavaScript files
| http://example.com/list | http://example.com/view/3 | http://example.com/edit/3 |
|---|
- jQueryBase
- ListView
- ListLocal
| - jQueryBase
- ListView
- ViewLocal
| - jQueryBase
- Form
- EditLocal
|
The benefits of grouping and combining over using individual files or a single combined file are:
- Sending less requests to the web server (as the files are now grouped and combined).
- Not downloading the same files between page visits (as when a single combined file is used and there are different components on each page).
- Downloading only the files that are required for the current page.
Compression
Telerik Extensions for ASP.NET MVC web asset support allows you to compress your JavaScript and CSS files. Compressed
web assets will save traffic bandwidth and speed up page loading time.
Important |
|---|
|
Compression works only for combined web assets (or asset groups), because it requires the HTTP handler which combines web assets.
|
Note |
|---|
|
Most modern browsers support compression. The only notable exception is Internet Explorer 6.0 - some
older minor versions do not properly support compressed JavaScript. As a result, the web asset HTTP handler
will not serve compressed output to Internet Explorer 6.
|
Caching
Telerik Extensions for ASP.NET MVC web asset support allows you to configure the time duration for which
the browser should cache the files.
Important |
|---|
|
Caching works only for combined web assets (or asset groups),
because it requires the HTTP handler, which combines web assets, to output the HTTP caching headers.
|
Content Delivery Network Support
Content Delivery Networks (CDN) improve the overal performance and latency of a web site
by hosting commonly used static resources (JavaScript, CSS and images).
Telerik Extensions for ASP.NET MVC web asset support allows you to transparently use CDN for your web assets. Once your
ASP.NET MVC application is ready, you can upload a web asset group to a CDN provider of your choice and then enable
CDN support for it. Here is how easy is that:
CopyC#
<%= Html.Telerik().ScriptRegistrar()
.Scripts(script => script.AddGroup( "jQueryBase", group =>
group.Add("~/Scripts/jquery-1.4.2.js")
.Add("~/Scripts/jquery-ui-1.7.2.custom.js")
.ContentDeliveryNetworkPath("http://mycdn.com/jQueryBase.js")
)
%> Important |
|---|
|
If CDN support is enabled, then combination, compression and caching settings of the asset group will not be
taken into account by the ScriptRegistrar. The CDN provider will control those settings.
|
See Also