---
title: Precompiling websites
related:
  - https://docs.kentico.com/k8/installation/deploying-kentico-to-a-live-server.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

When deploying a website, you have the option of [precompiling](http://msdn.microsoft.com/en-us/library/bb398860%28v=vs.90%29.aspx) the web project before you place it on a server. This compiles the project's code into assemblies, which provides several advantages:

- Faster initial response times - resources do not need to be compiled dynamically when they are requested for the first time.
- Source code protection - you can create a compiled version of the website without any accessible source code.

> **Note:** **Limitations of precompiled websites**
>
> Only use precompilation to deploy completed websites. Precompiled instances of Kentico have limited website development features.
>
> You cannot edit, create or import virtual objects that contain ASP.NET markup and require compilation:
>
> - [Page layouts](https://docs.kentico.com/k8/developing-websites/developing-websites-using-the-portal-engine/editing-page-layouts.md) (ASCX type)
> - [Transformations](https://docs.kentico.com/k8/developing-websites/loading-and-displaying-data-on-websites/writing-transformations.md) (ASCX type)
> - [Web part layouts](https://docs.kentico.com/k8/custom-development/developing-web-parts/using-custom-web-part-layouts.md)
> - [Form layouts](https://docs.kentico.com/k8/managing-website-content/forms/defining-custom-form-layout.md) (ASCX type)
>
> If you wish to [import](https://docs.kentico.com/k8/deploying-websites/exporting-and-importing-sites/importing-a-site-or-objects.md) physical files that require compilation (such as _cs_, _vb_, _aspx_, _ascx_), you need to run the import process on the original project, and then create the precompiled site again.
>
> [Partial caching](https://docs.kentico.com/k8/configuring-kentico/optimizing-website-performance/configuring-caching/caching-page-output.md) (i.e. caching portions of page output generated by specific web parts or controls) is not supported on precompiled websites.

## Testing the website before compilation

You can check that your site's virtual objects compile correctly before starting the precompilation. 

1. In the Kentico administration interface, open the **System** application.
2. Select the **Virtual objects** tab.
3. Click **Test virtual** objects.

The system compiles all virtual objects and adds them to the temporary files in the application's ASP.NET cache. This operation may take a long time, depending on the number of virtual objects in the system.

If the process finishes without errors, your website should run correctly after the precompilation.

## Precompiling web projects

1. In the Kentico administration interface, open the **System** application.
2. Select the **Virtual objects** tab.
3. Click **Store all virtual objects in file system**.
   - This saves all virtual objects into the web project as physical files, so they can be included in the precompilation.
   - On web application projects, you need to manually include the _CMSVirtualFiles_ folder into the _CMSApp_ project. See [Deployment mode for virtual objects](https://docs.kentico.com/k8/deploying-websites/deployment-mode-for-virtual-objects.md) for details.
4. Open your web project in Visual Studio (using the **WebSite.sln** or **WebApp.sln** file).
5. Right-click the Kentico project in the Solution Explorer and select **Publish Web Site**.
6. Prepare a publish profile according to your requirements. See [How to: Deploy a Web Project](http://msdn.microsoft.com/en-us/library/dd465337%28v=vs.110%29.aspx) for details.
7. On the **Settings** tab, expand **File Publish Options** and select **Precompile during publishing**.

   - Click **Configure** next to the check box and choose the compilation mode (**Allow precompiled site to be updatable**):
     - checked - compiles the code behind of all web forms and controls, but stores the markup files (.aspx, .ascx) in their original code form.
     - unchecked - the compilation also includes markup files. The website contains only empty "stub" .aspx/.ascx files without any code.

   > **Info:** We generally recommend using non-updatable sites for optimal performance.

   - In the **Merge options** section, select the _**Do not merge. Create a separate assembly for each page and control**_ option.
8. **Publish** the site.

> **Info:** Alternatively, you can use command line tools to perform the precompilation and merging of assemblies:
>
> - [ASP.NET Compilation Tool](http://msdn.microsoft.com/en-us/library/bb398860%28v=vs.110%29.aspx#PerformingPrecompilation)
> - [ASP.NET Merge Tool](http://msdn.microsoft.com/en-us/library/bb397866.ASPX)

### Moving the database

You may need to copy the database to the server using the standard **backup/restore** procedure, since the compiled website cannot be used to install an SQL Server database. Other options are:

- Install a non-compiled website on the server first, go through the setup wizard and then replace the non-compiled files with compiled ones, while keeping the web.config file.
- Install Kentico locally and run the [database setup](https://docs.kentico.com/k8/installation/additional-database-installation.md) against the remote SQL Server on the live server.
