.NET Array Dictionary List String 2D Async DataTable Dates DateTime Enum File For Foreach Format IEnumerable If IndexOf Lambda LINQ Parse Path Process Property Regex Replace Sort Split Static StringBuilder Substring Switch Tuple
Precompilation improves performance on some ASP.NET websites. It can be used to optimize static sites. We explore strategies for other types of sites. This speeds up the first access to pages in your site.
Intro. We will use precompilation options and walk through some of the Visual Studio 2008 user interface options. First, here are some of the options you have available in ASP.NET 2.0, and what they mean.
Classic precompilation: Aspx pages are not precompiled, but .cs classes and code-behind files are precompiled.
Dynamic compilation: This is the easiest to deploy but the slowest to run. Everything in the site is compiled once when it is first needed.
Site precompilation: The whole site is compiled—every markup aspx page, every .cs file, everything. Extremely fast but harder to deploy.
Static site. For a static site, it is a good idea to use site precompilation. This is where the entire site is fully compiled before being deployed. This is best for static sites or popular sites.
Many popular sites have hundreds of pages, and compiling each one before serving it would be costly. Precompilation avoids all of that because you pay the compilation price all at once on your development machine.
Set mode. You can set the precompilation mode by following these steps. First, you probably don't need to run any command-line tools. Here we use Visual Studio 2008 and ASP.NET. It is a little confusing, but that is why this article exists.
Note: We assume you are using a Website project type in Visual Studio 2008 or a later version.
Open your website project. This is easily done just as you open any project. Once you are ready, click on the Build menu, and then select the Publish Web Site option. The next thing you will see is the dialog, which is shown above.
Precompile dialog. What wording does the dialog use? Publish builds your website so that you can upload it to the server. It does not require that you upload your site. Here are some notes about the FTP uploading mechanisms you can use.
Target Location: This is where the published site will be put. I suggest using a location on your C:\ directory.
Allow this precompiled site to be updatable. Your website is updatable if you do not compile it into a big assembly before you deploy it.
Use fixed naming and single-page assemblies. Fixed naming is always the same. It will allow you to easily replace old assemblies.
The first check box above, "Allow this... to be updatable" is actually Microsoft's way of saying "Use dynamic compilation". With this option, all of your pages will be compiled at the last moment. This can be slow.
Site precompilation. If you want the faster option for the site once deployed, please consider "site precompilation." Let's assume your site is high-volume, popular and important. It is important that the site respond instantly when a customer visits.
Check target location. The target publish location is probably already set, but if it isn't, set the target location to your C:\ drive.
Updatable: Allowing your site to be updatable will make it slower. Therefore, for site precompilation uncheck this box.
Use fixed naming: Fixed naming makes it easier to drag and drop your new DLL to the old DLL location and replace the files.
Verify that it worked. Open your Projects folder in the Documents > Visual Studio 2008 folder. Check the PrecompiledWeb folder.
The Web Application project type is another model for creating ASP.NET sites. It does not have the same precompiled options, but you can use Publish for the same effect. More information about this project type is available.Web Application Project
Caution: Your C# (.cs) code files are mutually exclusive with site precompilation.
If you upload your site and leave the App_Code folder with code, it won't work. If you upload a precompiled web site, delete all of the App_Code and C# files. Otherwise, you will get mysterious runtime errors.
FTP. You can use FileZilla for FTP. I recommend FileZilla over most other options. It is a reliable piece of software and works well. Check out the FileZilla download site for the binaries.
Note: When you are ready to use FTP, you will need to copy all the files to your website directory.FileZilla: filezilla-project.org
Summary. We enabled precompilation and avoided completely the delays on each page when they are first loaded. You don't need to do anything with aspnet_compiler.exe, and can just use the GUI for your project.
Thus: You may see impressive improvements in site performance with precompilation.