I am developing a site which includes several different javascript files and libraries. For optimization purposes I have implemented YUI Compressor for .Net
This will minimize and combine my javascript files into one single file.
Now I have put this up in a MSBuild script that automatically does the compression and minimization and outputs it to a file of my choosing. However, I still wish to keep the original javascript files in my development environment. My question is simply:
Is there a good way to depending on the Debug setting for example choose which javascript to use? This to not have to change the MasterPage by hand each time I release the build.
Allow me to illustrate.
If I am running in Debug=”true” I wish my MasterPage to include the following javascripts:
<script type="text/javascript" src="first.js"></script>
<script type="text/javascript" src="second.js"></script>
<script type="text/javascript" src="third.js"></script>
<script type="text/javascript" src="fourth.js"></script>
If I am running in Debug=”false” I wish this to be outputted in the MasterPage:
<script type="text/javascript" src="compressedAndMinimized.js"></script>
Is there an elegant solution to this that I am missing here?
You can use preprocessors:
In my project, I define the platform (e.g. “local”, “development”, “beta”, and “production”) in an environment variable and access it via a Config class, but I suppose checking for debug/release mode works too.
EDIT
According to #DEBUG Preprocessor statements in ASPX page, the DEBUG variable used in ASPX files is pulled from Web.config, not your project’s current build configuration. This might still be usable to you, but your deployment script would need to change your Web.config when deploying to production.