The below script enables you to warm up staging slot before swapping the slot with production slot, this approach helps you to minimize the loading time of the app post swap.
$ServerErrors = 0
Start-Sleep -s 10
do {
$StatusCode = 0
$IsFail = $false
try {
$Page = Invoke-WebRequest $(StagingSiteUrl) -TimeoutSec 10 -UseBasicParsing
$StatusCode = $Page.StatusCode
}
catch [System.Net.WebException] {
if ($_ -like "*This web app is stopped*" -or ($_ -like "*The operation has timed out*")) {
Write-Host "Site not up yet"
Start-Sleep -s 10
}
else {
$Response = $_.Exception.Response;
if ($Response.StatusCode -eq [System.Net.HttpStatusCode]::InternalServerError -and $ServerErrors -lt 30)
{
$ServerErrors++
Write-Host "Site has an error"
Start-Sleep -s 10
}
else {
$IsFail = $true
Write-Error $_.Exception.Message
}
}
}
} until ($StatusCode -eq 200 -or $IsFail)
if ($StatusCode -eq 200) {
Write-Host "Site is up"
}