3.10. Better JavaScript

As you leverage JavaScript more in creating richer Web applications, a few practices may help you produce more robust and faster pages. For all of the advantages JavaScript brings, it also has some drawbacks that become apparent the more predominant a part of the page it becomes. The amount of script in a page can easily surpass the amount of HTML. Performance can start to lag.

Figure 3-15. Figure 3-15

3.10.1. Reducing Script

With bigger quantities of script being used in the page, the size of the script itself can become an issue. IIS supports compressing responses, but it is not turned on by default. Text compresses very well, which greatly reduces the number of bytes sent to the client. To enable compression in IIS, access the Internet Services Manager plug-in for the Microsoft Management Console. You can do this by entering inetmgr in the run dialog in the start menu. Right-click the Web Sites folder and select Properties. Options for enabling static and dynamic content are on the Services tab. There is CPU cost associated with compression, so you may want to enable it only for static content if the dynamic content is not cacheable (since the static content is always cacheable, it can be compressed once and not repeatedly).

Another technique for reducing the size of the script is variable substitution. You see this referred to as script compression. ...

Get Professional ASP.NET 3.5 AJAX now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.