Category Archives: Javascript

Simplify CSS and Javascript Compression In Visual Studio

I’ve released a new open source tool that performs design-time compression of your CSS and Javascript files in Visual Studio projects.  This can be a big help, since it allows you to easily do it in your project rather than as part of your build/publish process.  And, since it leaves both the compressed and uncompressed versions in place, you can still use the uncompressed version for debugging.

Read more about this new tool or download it at

jQuery.themescript 1.1.0 Released

Today I’ve released version 1.1.0 of jQuery.themescript.  This release includes some significant improvements that make it far more functional in the real world.

The original design concept was for a web store framework I was working on.  I wanted each store be able to easily change their javascript based themes without making changes to the javascript files for the basic theme.  This made for a much easier file based deployment of new versions to each store.  The obvious downside is that you’re downloading lots of extra javascript, particularly if you’re turning features back off that were in the basic theme.  This type of functionality is only useful in certain cases, and is never the most efficient system possible with regards to performance and bandwidth, just maintainability.

This new release still maintains that basic functionality, but now I address a more common concern as well, applying themes to AJAX updates.  In order to support this, I’ve added several new features.

  • $.themescript.exec now accepts a context parameter.  This can be a jQuery object or an HTML DOM element, just like the context to jQuery’s jQuery(selector, [context]) selector function.  All registered functions will receive this context as a parameter, and it will be automatically used as the context to selector-based theming to restrict the elements returned.
  • themescript is a new function added to jQuery objects which allows you to execute the themescripts against a specific jQuery object.  $(‘#selector’).themescript() is equivalent to $.themescript.exec( $(‘#selector’) )
  • themescript( url, [data], [callback] ) works just like the jQuery load method, except that it will automatically run themescripts against the updated HTML if the request is successful.

You can also easily add support for jQuery.themescript to ASP.Net AJAX partial page updates (a.k.a. UpdatePanels).  Just add this script code to your files and the themescripts will be automatically executed against any UpdatePanels which are changed during an asynchronous postback.

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(function(sender, args) {
    var</span> updated = args.get_panelsUpdated();
    if</span> (updated && updated.length) {

Here are the links where you can access the GitHub repository or download the files:


LABjs.Net Release Candidate 1.0rc4

I’ve committed release candidate 4 of LABjs.Net at GitHub.  It contains a few minor bug fixes, and also adds a few useful features.

  • LabScriptCombine allows you to make use of the automated runtime script combining features of ASP.Net 3.5 in combination with LABjs script chaining.  To get the optimum script load time, combine scripts between each wait() call into a single HTTP request, so long as you are consistently using that combination of scripts across your pages.
  • Added some useful constructors to several of the LABjs.Net classes.  These constructors make it easier to build a LABjs chain in your code rather than in your .aspx files.
  • Made a slight change to the LabWait constructor that accepts an inlineScript parameter.  It will now default DetectScriptTags to False if you use this constructor, since you shouldn’t be including the script tags if you are building your chain in code.  You can still set this Property back to True if needed.
  • Added AlternateRef property to LabScriptReference.  If you’re using the experimental CDN failover extension to LABjs, it allows you to specify a full set of options for the alternate script.  The AlternateRef property allows you to make use of those options if you want to, by providing a full LabScriptReference class to use.  This is optionally used instead of the simpler Alternate property that just provides a URL.


Simplify Asynchronous Javascript Loading In ASP.Net Using LABjs

LABjs is an excellent javascript library that performs asynchronous loading of javascript files. This can help to greatly increase the load speed of your web pages. Now, instead of blocking while one file is being downloaded, other scripts further down the chain can be downloaded while waiting. On top of that, it can maintain processing order, waiting to process certain scripts until others are complete, and optionally executing code on completion.

All of this is great for the client side. But how do you define which scripts to include in the LABjs chain on the server side?

Since for work I primarily operate in ASP.Net, I’ve created an ASP.Net solution to the problem, LABjs.Net. This library provides two key controls, LabScriptManager and LabScriptManagerProxy. These controls loosely follow the behavior of the AJAX ScriptManager and ScriptManagerProxy controls, at least their script loading aspects.

Key supported features include:

  1. Refer to script files using application relative paths (i.e. ~/js/jquery.min.js)
  2. Load script files from assembly resources
  3. Specify if debug or release scripts should be used, or use the debug setting from the web.config file
  4. Ability to set any of the options provided by LABjs
  5. Include wait() calls in the chain, and provide inline functions to be executed after the wait
  6. Use LabScriptManagerProxy to add scripts and waits to the chain in content pages and user controls
  7. Use LabActionGroup inside LabScriptManagerProxy to add script() calls at a specific point in the primary chain
  8. LABjs debug and release versions are embedded in the DLL and automatically referenced, but you can opti0nally override this with your own URL
  9. Experimental support for the cdnLABjs library I am working on, which provides automatic failover to a local file if a file fails to load from a CDN (for information about why, see Using CDN Hosted jQuery with a Local Fall-back Copy)

Below you will find links to the current release candidate, 1.0rc1.  Please review it and give me any feedback you might have.

Download Binaries
Readme File
Git Repository

Update 2/8/2010: Updated to version 1.0rc4