Jan 10 2007

IncludeScriptCompression

Posted by admin under ASPCodeHeaderManager

How dows it work?

1. If appsettings debugmode = true then it never compresses the javascript file but instead just sets the script src='' path directly to the script.

i.e

<headermanager:IncludeScript Path="~/scripts/hello.js" />

----->

<script type="text/javascript" src="/www/scripts/hello.js">

2. However if debugmode = false then we look at IncludeScriptsCompression. If set to 0 then same as in step 1. If set to 1 or 2 then we rewrite the path:

<headermanager:IncludeScript Path="~/scripts/hello.js" />

----->

<script type="text/javascript" src="/www/aspcodescripts/getopt.ashx?f=/www/scripts/hello.js"></script>

Now our handler is called instead. That code is found in JSHandler.cs - I basically read the file from disk - packs it according to IncludeScriptsCompression (using Dean Edwards excellent packer)  and then just returns it as contentype=text/javascript.

However - packing requires that the javascripts are semantically correct - you might get strange results otherwise. You might find that a certain thirdparty js you are using is not functioning when packed - so please look at the davanced section on how to override packing for specific files.