-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSiteWarmup.ps1
63 lines (46 loc) · 1.98 KB
/
SiteWarmup.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# sitemapFile - location of the XML Sitemap
# statusFile - location of the status file. Progress is written here. Place somewhere in website root so you can open using a web browser to see current status. If empty, placed in same folder as this script
# logFile - location of the log file. All URLs are logged here with their HTTP status code and response time. Recommend placing in App_Data. If empty, placed in same folder as this script
param([String]$sitemapFile, [String]$statusFile, [String]$logFile)
# Multi-threading library
$MyDir = Split-Path $MyInvocation.MyCommand.Definition
. "$MyDir\Invoke-Parallel.ps1"
$startTime = Get-Date
if([string]::IsNullOrEmpty($logFile)) { $logFile = "$MyDir\log.csv" }
if([string]::IsNullOrEmpty($statusFile)) { $statusFile = "$MyDir\status.txt" }
if(Test-Path $statusFile) {
Clear-Content $statusFile
}
$pages = @()
# Collect page urls for processing
""
"Collecting page urls..."
[xml]$xml = Get-Content $sitemapFile -ReadCount 0
foreach ($urlCollection in $xml.urlset.url)
{
if($urlCollection.link -eq $null)
{
# No language variation, just use the default location
$pages += $urlCollection.loc.ToLower()
} else {
# Loop through all language variations
foreach ($link in $urlCollection.link)
{
$pages += $link.href.ToLower()
}
}
}
"Sitemap count:" + $pages.Count
""
$pages | Invoke-Parallel -LogFile $logFile -ProgressFile $statusFile {
$url = $_
# create a web request with browser cache disabled
[System.Net.HttpWebRequest] $request = [System.Net.HttpWebRequest]::Create($url)
$request.Method = "GET"
$request.Timeout = 21600000
$request.CachePolicy = New-Object System.Net.Cache.HttpRequestCachePolicy([System.Net.Cache.HttpRequestCacheLevel]::NoCacheNoStore)
$request.UserAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::Chrome
[System.Net.HttpWebResponse] $response = $request.GetResponse()
$response.Close()
}
"Warmup completed"