What is a Warm-Up Script

In a SharePoint production environment hosted in IIS, AppPool recycling on a daily basis is considered good practice.
But as an after-effect of AppPool-recycle, when the first user hits the sites of the corresponding SharePoint Web application, slowness is experienced. This is because of the ASP.NET's dynamic page compilation and page caching which happens when the first user hits the page after an IISRESET/AppPool Recycle. But the subsequent users will not face the problem of slowness and pages load faster.

To provide a better and faster browsing experience even to the very first user, many organizations take the help of a Warm up script which does the job of hitting the pages for the first time .In this article I am writing a sample warm-up script which can be modified and used as per requirement.

How-To write a Warm Up script

Here I am writing it in VB Script. Once the script is ready, it will be added as a scheduled task in all web servers present in the SharePoint farm. Apart from hitting the mostly visited pages, the script also logs the status into a text file based upon the http response .From the logs one can make out, if the script has run properly or not.

Section 1:
Declare variables to hold site urls.Here let's say I have got two sites to warm up.

site1="http://Web-Application Name:port/Site1/Pages/default.aspx"
'Site 2
site2="http://Web-Application Name:port/Site2/Pages/default.aspx"

Section 2:
Write a function to make HTTP calls to above urls and write the responses to a log file.In case of intranet-based applications where Windows authentication works,we need to provide userid and password of a domain account using which the GET/Post request will be sent.

Function WarmUp(url)
    On Error Resume Next
    Dim objHTTP
    Set objHTTP= CreateObject("Microsoft.XMLHTTP")
    objHTTP.Open "GET",url,False,<<userid>>,<<password>>
    If Err.Number=0 And objHTTP.Status=200 Then
        Hget=url & "has been warmed up successfully at :"& Date()&"  "& Time()
        Hget=url & "found error at :"& Date()&"  "& Time()
    End If
    Set objHTTP = Nothing
    'Section for writing into a text file
    Const FOR_APPENDING = 8
    strFileName = "C:\\scriptlogs\service_status.txt"
    Set objFS = CreateObject("Scripting.FileSystemObject")
    Set objTS = objFS.OpenTextFile(strFileName,FOR_APPENDING)
    objTS.WriteLine Hget
End Function

Section 3:
Function Call


Write these three sections in a notepad and save it with .vbs extension.

Then add this script as a Scheduled task in all web front end servers.The timing to run the script should be around 1 or 2 minutes after AppPool recycle.This is how a warmup script can be created for a SharePoint site.Hope this is helpful.

See Also