Tales from the Evil Empire

Bertrand Le Roy's blog

News

Ads Via DevMavens

ASP.NET AJAX UpdatePanel Control: Add Ajax interactivity to your ASP.NET 2.0 web pages

Add to Technorati Favorites

Blogs I read

My other stuff

Script reference profiler

ASP.NET Ajax 3.5 SP1 contains a new feature that enables the application developer to combine scripts in order to reduce the number of downloaded files. But in order to do that, the developer must have a way of discovering what scripts are being used in a page or application.

To make that easier, I've developed a small control that you can drop onto a page and that will render out the list of script references that are being used by the page. It is then easy to copy and paste that list into the CombinedScripts property of the script manager and combine all those references into one.

The control also renders two links that enable the developer to download the debug and release versions of the combined scripts. Those scripts can be downloaded, copied into the site and used with the Path property on CombinedScripts. This enables better server performance than the plain automatic combination that ScriptResource.axd performs, but it also means you need to re-generate that file every time any of the scripts change.

The project to build the control can be downloaded as part of the ASP.NET CodePlex project:
http://www.codeplex.com/aspnet/SourceControl/DirectoryView.aspx?SourcePath=%24%2faspnet%2fAJAX%2fFutures%2fScriptReferenceProfiler&changeSetId=7061

UPDATE: the component can also be downloaded in binary form from here:
http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=13356

Comments

rachitp said:

Awesome control...

# June 12, 2008 10:10 PM

J Shissler said:

This is a good idea.  I am curious where the combined script is stored and if the resulting JavaScript is minified (which would be really great).   I assume that this feature could be used by a page that does not use ASP.NET Ajax as long as the developer puts a ScriptManager control and adds any application .js files that are normally included on the page, correct?

# June 13, 2008 3:41 PM

Bertrand Le Roy said:

@J: The combined script is not exactly "stored". It is being generated by a handler dynamically (and output-cached). The JavaScript is not minified by the handler, but the infrastructure allows for a release and a debug version of each script, the release version being minified using one of the many tools available. You could use that with non ASP.NET Ajax frameworks if the scriptmanager didn't always include MicrosofAjax.js (which is something we're looking at relaxing in a future release).

# June 13, 2008 4:46 PM

Andrei Rinea said:

Although it is a great idea and I'm sure it took a lot of effort to build the tool, I'm quite skeptical about the amount of performance gain obtained.

How much do you really gain from this? Bandwidth and/or lag time?

# June 13, 2008 6:46 PM

Bertrand Le Roy said:

@Andrei: you're absolutely right, the gains are most of the time quite modest, but it does add up on a high traffic site. Definitely not a feature that you need to use on each and every site, and definitely one you should use with caution.

# June 13, 2008 6:52 PM

Daniel Brünteson said:

Hi Bertrand,

What about forcing the javascript's to load after the GUI, "loadscriptsbeforeui='false'", which has an even greater effect on what you perceive as performance, does this work with that? In 3.5 w/o SP1 it's not working completely well.

# June 14, 2008 3:39 AM

J Shissler said:

Thanks for the clarification, Betrand. My thought on this was that it could provide the mechanism to logically combine scripts into a single HTTP request while still allowing one to have separate physical files for easier maintenance, debugging, optional inclusion on the pages that need them, etc.  Does output-caching allow the Expires and related HTTP headers to be set or is the resulting single file always fetched from the server cache?

# June 16, 2008 8:48 AM

Bertrand Le Roy said:

@Daniel: loadscriptsbeforeui should just work. If it doesn't, it's a bug and you can send me a repro using the contact form on this blog.

@J: You can combine multiple physical script files using that feature, but we really don't recommend it as there is some server overhead related to file monitoring. What you're describing is much better handled by "building" your scripts at compile time instead of doing the combination at runtime. The feature really is for application developers who want to combine existing scripts from various components that they use in their application.

The output caching expiration is set by the handler. The resulting files are cached at all levels, including client-side. The efficient client-side caching is made possible by the fact that the combined url varies every time one of the underlying files changed.

# June 16, 2008 3:43 PM

Peter said:

I've tried Telerik's SM that has this same feature and I have noticed quite a bit of improvement. The benefit is in the reduction of the chatter between the client and server. When you have more than 10 JavaScript includes and you reduce that to only a couple you will feel the difference.

It is, however, debatable how useful it is. Yes, it will make the first access much faster, but if on page 1 you load scripts A through G, and on page 2 you want A through G and M, since it's all bundled, it will have to load the whole pack one more time. not just M. I guess it depends on your scenario.

As far as compression: People please enable the built-in IIS (v 6 and 7) compression. It's there and it's quite good. You get the biggest bang for the buck just by enabling the compression (off by default in IIS6, not sure about IIS7).

# July 10, 2008 12:44 AM

Bertrand Le Roy said:

@Peter: that's why you need to profile your application, not just a page. Which is why, in turn, we didn't make the feature all automatic because it would have made more harm than good in some cases.

You're right about dynamic and static compression in IIS7, it's one of the most efficient ways to improve perf, but good perf is ultimately a combination of several things. I recommend reading "high performance web sites" by Steve Souders for a pretty comprehensive set of tricks along those lines.

# July 10, 2008 1:12 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)