You want to improve the performance of ASP.NET website by using precompilation. Optimize static sites to use site precompilation, and explore strategies for other types of sites. This speeds up the first access to pages in your site. Here we see ways to precompile your websites in ASP.NET.
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 really mean. Next we will see what kinds of sites the following options are best for, and also some of their drawbacks.
Classic precompilation. A cross between the other two modes. *.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. Every page will be slow until it has been visited once.
Site precompilation. The whole site is compiled—every markup aspx page, every .cs file, everything. Extremely fast but harder to deploy.
Site precompilation. This is where the entire site is fully compiled before being deployed. This is best for static sites or very popular sites. Many popular sites have hundreds of pages, and compiling each one before serving it would be very costly. Precompilation avoids all of that because you pay the compilation price all at once on your development machine.
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. In this section we assume you are using a Website project type in Visual Studio. [See Web Application link below.]
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.
Window shows up. The next thing you will see is the dialog, which is shown at the top of this article. This is confusing, but mastering it is rewarding. This is where we set the compilation options.
You must understand the wording the dialog uses. What Publish does is build 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 near the end of this article.
Target Location: [Text input box] This is where the published site will be put. (The author suggests using a location on your disk C:\ for now.) "Allow this precompiled site to be updatable" [X] This indicates whether you want to use dynamic compilation or not. Your website is only updatable if you do not compile it all into a big assembly before you deploy it. "Use fixed naming and single-page assemblies" [X] Fixed naming is naming that is always the same. The author recommends this as it will allow to easily replace old assemblies on the server. "Enable strong naming on precompiled assemblies" [X] This is a security option.
Points on options. There are a couple points about these options the author wants to stress. The first checkbox 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 very slow.
If by fastest you mean for the site once deployed, then we must use "site precompilation." Let's assume your site is high-volume, popular, and important to you. It is important that the site respond instantly when a potential customer comes along. Definitely use site compilation. Here are the steps to enable site compilation.
Check target location. The target publish location is probably already set, but if it isn't, set the target location to your C:\ drive.
Uncheck "updatable" box. Allowing your site to be updatable will make it slower. Therefore, for site precompilation uncheck this box.
Check "use fixed naming". Fixed naming makes it easier to drag and drop your new DLL to the old DLL location and replace the files. That's all this option is good for, but this is really handy and it is best to use fixed naming.
Verify that it worked. Open your Projects folder in the Documents > Visual Studio 2008 folder. Your precompiled site will be in the folder corresponding to your site's name. It should be in the PrecompiledWeb folder.
Note on Web Application projects. 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.
(See Web Application Project Comparison.)
Your C# (.cs) code files are mutually exclusive with site precompilation. If you upload your site and leave the App_Code folder with code in it, 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.
With FileZilla. FTP is a tricky business and you are on your own here. The author recommend FileZilla over most other options—it is a great piece of software and works well. Check out the FileZilla download site for the binaries. When you are ready to use FTP, you will need to copy all the files to your website directory.
(Visit filezilla-project.org.)
Here we enable precompilation and avoid 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. You may see very impressive improvements in site performance with precompilation.