Best practices: Precompilation
When you run the Precompiler tool, it gets the markup of all pages, compiles it, and creates an assembly with the precompiled pages. Whenever a page is requested, it is directly loaded from the created assembly. Any change to a page, such as publishing or editing the page template, invalidates its cached compiled assembly. In this case, the page is compiled the next time it is requested and is added to a dynamically generated satellite assembly. On every subsequent request, the page is loaded from this satellite assembly. However, if you make any change to the bin folder of your project, the satellite assembly is deleted. This way, the page compilation process will be repeated on the next request.
Because compilation is slow, the first request of a page that is not in the assembly, generated by the tool, or in the dynamically generated assembly, can take a substantial amount of time. Whenever a page is requested and not found in any of the assemblies, a message is logged in the Trace.log
file. For more information, see Administration: Precompilation log.
You can use this log to check whether the page is loading slowly, because it is not precompiled.
The message contains the page title, the page ID, the culture, and the compilation time.
EXAMPLE: Message: Compiled page Dashboard, ID - "45d368fb-a8a8-4cb0-8929-9f5d2f788882", Culture - "" - 00:00:02.51)
Best practices
Following are some best practices to follow when to take care of the proper precompilation of your pages:
- Always run the tool before deploying to live. Set the URL to point to the live site and the application folder path to the dev directory.
- Act with caution when making a change in the bin folder. You can run the Precompilation tool afterwards.
- Act carefully when editing a Sitefinity template, because it will invalidate all pages that use it and they will be compiled the next time they are requested.