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 translations Article translations
Article ID: 933823 - View products that this article applies to.
Expand all | Collapse all

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://ServerName/_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 "_layouts" folder. For example, a page that the system-master page uses may be called the "/_layouts/Settings.aspx" 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.
To create a new page that downloads the Core.js file but that does not reference the Core.js file, follow these steps:
  1. 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 "ArticleLeftNoCore.aspx."

    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:
    1. Double-click the new page layout. For example, double-click ArticleLeftNoCore.aspx. Then, at the bottom of the page, click Code.
    2. Locate the PlaceHolderAdditionalPageHead tag, and then add the following code to the tag.
      <SharePointWebControls:ScriptLink runat="server"/>  
      
      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 "SharePoint:ScriptLink" tag instead of the "SharePointWebControls:ScriptLink" 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="SharePointWebControls" 
      Namespace="Microsoft.SharePoint.WebControls" 
      Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, 
      PublicKeyToken=PublicKeyToken" %> 
  2. Create a new binary that is based on the following code. For example, create a new binary that is named "PerfTools.dll."
    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("Text")]
        [ToolboxData("<{0}:RegisterCoreWhenAuthenticatedControl runat=server></
    {0}:RegisterCoreWhenAuthenticatedControl>")]
        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:
    1. Set the version of the binary to 1.0.0.0.
    2. Add the binary to the global assembly cache on the server.
  3. Open the Web.config file on the server, and then add the following code to the set of SafeControls controls.
    <SafeControl Assembly="PerfTools, Version=1.0.0.0, Culture=neutral, PublicKeyToken=PublicKeyToken" Namespace="WebControls" TypeName="*" Safe="True" />
  4. In the new page layout that you created in step 1, follow these steps:
    1. Add a tag to register the binary. The following tag is an example of such a tag.
      <%@ Register TagPrefix="PerfTools" Namespace="WebControls" 
      Assembly="PerfTools, Version=1.0.0.0, Culture=neutral,
      PublicKeyToken=PublicKeyToken" %>
    2. On the line after the code that you added in step 1b, add the following code.
      <PerfTools:RegisterCoreWhenAuthenticatedControl runat="server"/>
  5. Create a new page that is named "CorePreLoad.aspx," and then copy it to the "_layouts" folder on the server.

    Use the following code to create the page.
    <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" 
    Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, 
    PublicKeyToken=71e9bce111e9429c" %>
    <html>
    <head>
    <title>Pre-Load Core.js</title>
    </head>
    <body>
    <SharePoint:ScriptLink name="core.js" runat="server" />
    
    <script language="javascript">
     DisableRefreshOnFocus();
    </script>
    
    </body>
    </html>
    
    This page references a function in the Core.js file. Additionally, the page downloads the Core.js file before it runs the file.
  6. Open the master page, and then add the following code after the </form> tag and before the </body> tag.
    <asp:ContentPlaceHolder id="PlaceHolderBottomIFrame" 
    runat="server" />
  7. In the new page layout that you created in step 1, add the following code to the end of the page.
    <asp:Content ContentPlaceholderID="PlaceHolderBottomIFrame" 
    runat="server">
                    <iframe 
    src="http://blogs.msdn.com/_layouts/CorePreLoad.aspx" 
    style="display:none"/>
    </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.
  8. Check in the new page layout, and then publish it.
  9. 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.
  10. 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.
  11. 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.
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.

REFERENCES

For more information about this procedure, visit the following Microsoft Web site:
http://blogs.msdn.com/ecm/archive/2007/02/21/building-a-new-page-layout-which-does-not-reference-core-js-but-downloads-it-while-the-page-is-being-viewed-thereby-optimizing-response-time.aspx
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

Properties

Article ID: 933823 - Last Review: May 15, 2007 - Revision: 1.2
APPLIES TO
  • Microsoft Office SharePoint Server 2007
  • Microsoft Office SharePoint Designer 2007
Keywords: 
kbhowto kbexpertiseinter kbinfo KB933823

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com