Skip to main content
Home  ›  Blog

The Trouble with DNN JavaScript / CSS Minification (aka Client Dependency/Resource Management)

(Opinion) For years now 2sxc has promoted the merits of the DNN Client-Dependency-Management, and tried to use it wherever possible + recommended it in blogs. In reality, it hurt us badly. Bogdan from DNNSharp showed me a better way - so 2sxc now officially stops doing this, and recommend that you evaluate if this is important for you too.

What is the Client Dependency Management?

Basically it's a system in DNN which should be told what CSS / JS files the page will use, and then delivers them all in one single request. Combined, minified and zipped, from the server to the browser. It also takes care of the sequence of loading things, to ensure that the order of items works - so that jQuery is loaded before your stuff, etc. This should improve performance and reliability. So basically it does a few core things

  1. Ensure that each script is only included once (if multiple components need a script, it will only be added once)
  2. Attempt to order the scripts correctly (so that jQuery comes before your script)
  3. Attach all files into one file
  4. Do some minification / zipping
  5. Cache this combination of files

Registering a Script using ASP.net

public static void RegisterJs(Page page, string version, string path)
{
    var url = string.Format("{0}{1}v={2}", path, path.IndexOf('?') > 0 ? '&' : '?', version);
    page.ClientScript.RegisterClientScriptInclude(typeof(Page), path, url);
}

What's Missing in Page.ClientScript

Some things are missing in this, so bear with me while I tell you what is left to do:

  1. Ensure the script is only included 1x - check!
  2. Order the scripts correctly: nope, won't happen. So you should never use this for global, dnn-shared scripts like jQuery, best leave those to DNN to handle them. But it's perfect for everything that comes from you.
  3. Merging into one file: nope, but that's a good thing. Use Gulp/Grunt instead, it's much, much better.
  4. Minification: nope, but that's a good thing. Use Gulp/Grunt instead, it's much, much better.
  5. Zipping: nope, but again a good thing. Use the IIS functionality instead, it's (imho) better.
  6. Caching: not necessary; the browser can cache JS very, very well - and the server doesn't need an additonal cache

What about CSS?

Sorry, not supported. You are either stuck with the DNN-Mechanism, with multiple-includes or with some self-handcrafted solution. BUT you should still use Gulp/Grunt to better control the minification, again delivering a much better solution.

Rounding it Up

For us, this change took care of many, many support issues - and probably took care of many more issues that were never reported, but left users frustrated. Maybe it fits your solution as well, maybe not. And if you have better solutions, or something I was not aware of which would be way better - then share it - would love to hear from you.

Love from Switzerland,
Daniel


Daniel Mettler grew up in the jungles of Indonesia and is founder and CEO of 2sic internet solutions in Switzerland and Liechtenstein, an 20-head web specialist with over 800 DNN projects since 1999. He is also chief architect of 2sxc (see github), an open source module for creating attractive content and DNN Apps.

Read more posts by Daniel Mettler