5.4. Customizing the Location of Scripts

You've seen how you can provide Release and Debug versions of JavaScript files on disk, and the ScriptManager will automatically reference the correct version. And you've seen how to embed scripts in a .dll for easier servicing. ASP.NET AJAX also allows you to further customize script reference behavior.

5.4.1. Setting the Script Path

You may want to put the common scripts for nested applications in a single location to allow the browser to cache a single copy for multiple directories. Typically, ASP.NET AJAX returns relative path references for embedded script resources, so the browser can end up caching multiple copies of a script for different applications within the same domain. The ScriptManager's ScriptPath property allows you to define a path to use in lieu of the normal discovery process. This allows you to put the scripts in a single location and have all references in the domain refer to that location. This also has a performance benefit, because it is faster to load a static JavaScript file from disk than to extract it from an assembly through the ScriptResource.axd handler.

At first, this may not seem like much, but when you consider that, even compressed, the amount of script to enable ASP.NET AJAX scenarios is more than 10K, allowing each user to get just one copy instead of one for each subdomain or nested application can really add up. The perceived performance for the user in eliminating excess calls can be significant. ...

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.