Microsoft KB Archive/933823

= How to create a detached page that downloads the Core.js file but that does not reference the Core.js file on a SharePoint Server 2007 site =

Article ID: 933823

Article Last Modified on 5/15/2007

-

APPLIES TO


 * Microsoft Office SharePoint Server 2007
 * Microsoft Office SharePoint Designer 2007

-



SUMMARY
This article discusses an optimization procedure for Microsoft Office SharePoint Server 2007. The article describes how to create a detached page that downloads the Core.js file but that does not reference the Core.js file on a site. When you use this method, you can delay the download of the Core.js file for anonymous users until users can view the page. In this manner, the page is rendered more quickly.



INTRODUCTION
This article describes how to use Microsoft Office SharePoint Designer 2007 to create a detached page that downloads the Core.js file but that does not reference the Core.js file on a SharePoint Server 2007 site.

On an Internet-facing site, users who are on low-bandwidth connections or on high-latency connections may experience slow performance when they first browse a site. For example, it may take a long time for the first page of a site to load because of the additional resources that sometimes must be downloaded. Although resources are frequently shared between pages on a site, and although these resources are cached on the client, the first page of a site may be slow to load.

This article describes an optimization procedure for SharePoint Server 2007. By default, all pages on a SharePoint Server 2007 site contain a reference to the Core.js file. The Core.js file, in its compressed form, is 54 KB. In many areas, this file is critical to the operation of the site. However, there are some areas in which this file is not needed.

In the optimization procedure, you create a new page layout. Then, you create a new page by using that page layout. In the new page, the Core.js file is removed from the list of resources that must be downloaded before the page is rendered for an anonymous user. When content on the page is readable, the Core.js file is downloaded in the background.

Important The optimization procedure that is discussed in this article is not supported.



MORE INFORMATION
Before you perform this procedure, make sure that the following criteria are met:  The site-master page differs from the system-master page.

To verify this, locate the following page:

http:// /_layouts/ChangeSiteMasterPage.aspx

Then, determine whether the site-master page and the system-master page reference the same file. If they do reference the same file, the optimization in this procedure will not work. For the optimization to work, the site-master page and the system-master page must use different files.

Pages that the system-master page uses are typically in the &quot;_layouts&quot; folder. For example, a page that the system-master page uses may be called the &quot;/_layouts/Settings.aspx&quot; page. The site-master page does not contain the following controls:  Controls that are visible to anonymous users Controls that require the Core.js file but that do not register the Core.js file

The optimization in this procedure suppresses the Core.js file on one page, and it suppresses the file only for anonymous users. For anonymous users, the Core.js file is not downloaded to the page until after the page is readable. For authenticated users, the Core.js file is downloaded to the page before the page is readable.

You can modify the code that is mentioned in step 2 of the optimization procedure to suppress the Core.js file for users other than anonymous users. If you do this, you must also consider the site-master page. Make sure that the site-master page does not contain ScriptLink controls that register the Core.js file. The goal of this procedure is to create a page that suppresses the Core.js file.

Note Under typical circumstances, the Core.js file is registered by the SPWebPartManager control.</ul>

To create a new page that downloads the Core.js file but that does not reference the Core.js file, follow these steps: <ol> In SharePoint Designer 2007, create a new page layout. To do this, copy an existing page layout and then paste it to the same folder.

For example, copy ArticleLeft.aspx, and then name the new page layout &quot;ArticleLeftNoCore.aspx.&quot;

Note To distinguish between the two page layouts, you may want to specify a new description for the new page layout that you created.

After you create the new page layout, follow these steps: <ol style="list-style-type: lower-alpha;"> Double-click the new page layout. For example, double-click ArticleLeftNoCore.aspx. Then, at the bottom of the page, click Code.</li>  Locate the PlaceHolderAdditionalPageHead tag, and then add the following code to the tag. <SharePointWebControls:ScriptLink runat=&quot;server&quot;/> When you do this, the server does not reference the Core.js file unless the Core.js file is registered by a control.

Other master pages may use a different tag to reference the ScriptLink control. For example, the Default.master page uses the &quot;SharePoint:ScriptLink&quot; tag instead of the &quot;SharePointWebControls:ScriptLink&quot; tag.

The tag that references the ScriptLink control references the Microsoft.SharePoint.WebControls namespace. The following tag is an example of such a tag. <%@ Register Tagprefix=&quot;SharePointWebControls&quot; Namespace=&quot;Microsoft.SharePoint.WebControls&quot; Assembly=&quot;Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=PublicKeyToken&quot; %> </li></ol> </li>  Create a new binary that is based on the following code. For example, create a new binary that is named &quot;PerfTools.dll.&quot; using System; using System.Collections.Generic; using System.ComponentModel; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Microsoft.SharePoint; namespace WebControls

{   [DefaultProperty(&quot;Text&quot;)] [ToolboxData(&quot;<{0}:RegisterCoreWhenAuthenticatedControl runat=server></ {0}:RegisterCoreWhenAuthenticatedControl>&quot;)] public class RegisterCoreWhenAuthenticatedControl : WebControl {       protected override void OnInit(EventArgs e)        { if (HttpContext.Current.Request.IsAuthenticated) {               Microsoft.SharePoint.WebControls.ScriptLink.RegisterCore(this.Page, true); }           base.OnInit(e); }   } }  This code tells the server to reference the Core.js file if the user is not anonymous. This operation is performed because the Site Actions menu requires the Core.js file. By default, many authenticated users have access to the Site Actions menu on the site.

Your environment may require that you suppress the Core.js file under different circumstances. In this environment, use code that is appropriate to your needs.

Be aware that the OnInit method is run any time that the page is loaded. Therefore, make sure that you do not add code that adversely affects throughput on the server. For example, if you add code that accesses the current SpListItem component, a round trip to the Microsoft SQL Server database is likely to occur.

After you create the new binary, follow these steps: <ol style="list-style-type: lower-alpha;"> Set the version of the binary to 1.0.0.0.</li> Add the binary to the global assembly cache on the server.</li></ol> </li>  Open the Web.config file on the server, and then add the following code to the set of SafeControls controls. <SafeControl Assembly=&quot;PerfTools, Version=1.0.0.0, Culture=neutral, PublicKeyToken=PublicKeyToken&quot; Namespace=&quot;WebControls&quot; TypeName=&quot;*&quot; Safe=&quot;True&quot; /> </li> In the new page layout that you created in step 1, follow these steps: <ol style="list-style-type: lower-alpha;">  Add a tag to register the binary. The following tag is an example of such a tag. <%@ Register TagPrefix=&quot;PerfTools&quot; Namespace=&quot;WebControls&quot;

Assembly=&quot;PerfTools, Version=1.0.0.0, Culture=neutral,

PublicKeyToken=PublicKeyToken&quot; %> </li>  On the line after the code that you added in step 1b, add the following code. <PerfTools:RegisterCoreWhenAuthenticatedControl runat=&quot;server&quot;/> </li></ol> </li>  Create a new page that is named &quot;CorePreLoad.aspx,&quot; and then copy it to the &quot;_layouts&quot; folder on the server.

Use the following code to create the page. <%@ Register Tagprefix=&quot;SharePoint&quot; Namespace=&quot;Microsoft.SharePoint.WebControls&quot; Assembly=&quot;Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %> Pre-Load Core.js <SharePoint:ScriptLink name=&quot;core.js&quot; runat=&quot;server&quot; />

<script language=&quot;javascript&quot;> DisableRefreshOnFocus;

This page references a function in the Core.js file. Additionally, the page downloads the Core.js file before it runs the file. </li>  Open the master page, and then add the following code after the tag and before the tag. <asp:ContentPlaceHolder id=&quot;PlaceHolderBottomIFrame&quot; runat=&quot;server&quot; /> </li>  In the new page layout that you created in step 1, add the following code to the end of the page. <asp:Content ContentPlaceholderID=&quot;PlaceHolderBottomIFrame&quot; runat=&quot;server&quot;> <iframe src=&quot;http://blogs.msdn.com/_layouts/CorePreLoad.aspx&quot; style=&quot;display:none&quot;/> </asp:Content> This code enables the new page layout to reference the CorePreLoad.aspx page. All items on the page are displayed before the CorePreLoad.aspx file is loaded to perform its function. </li> Check in the new page layout, and then publish it.</li> Use the new page layout to create a new page.

When anonymous users browse the new page, the Core.js file does not have to be downloaded before the user can view the page or before the user can interact with the page.

For example, you use ArticleLeft.aspx to create a new page, and then you use ArticleLeftNoCore.aspx to create another new page. Although both new pages are identical, one new page references the Core.js file and the other new page does not.</li> Test the new page that you created to make sure that all controls work correctly.

If controls do not work when anonymous users browse the page, remove the controls from the new page. Alternatively, remove the controls from the new page layout. The optimization in this procedure assumes that the new page does not require the Core.js file because no items on the page require the Core.js file.</li> <li>Make sure that the Core.js file still appears on other pages on the site. Browse other pages on the site to verify that the Core.js file appears on those pages.</li></ol>

To verify that the optimization in this procedure works correctly, browse the new page as an anonymous user, and then view the source code on the page. Confirm that a reference to the Core.js file does not exist. Then, view the cache. Confirm that the Core.js file is downloaded to the server. Only the page that you created from the new page layout does not reference the Core.js file. Other pages on the site will continue to reference the Core.js file.

<div class="references_section">