パフォーマンスに関するヒントがいくつかありますが、HTTPヘッダーを使用してクライアント側でレスポンスをキャッシュできます。また、応答を送信する前に、白い領域の除去方法を使用して出力することもできます。別のポイントは圧縮です:ブラウザがサポートしている場合は、応答を圧縮します。
Private Function StripWhitespace(ByVal body As String) As String
body = body.Replace(" ", " ")
body = body.Replace(Environment.NewLine, [String].Empty)
body = body.Replace(vbTab, String.Empty)
body = body.Replace(" {", "{")
body = body.Replace(" :", ":")
body = body.Replace(": ", ":")
body = body.Replace(", ", ",")
body = body.Replace("; ", ";")
body = body.Replace(";}", "}")
' sometimes found when retrieving CSS remotely
body = body.Replace("?", String.Empty)
'body = Regex.Replace(body, @"/\*[^\*]*\*+([^/\*]*\*+)*/", "$1");
body = Regex.Replace(body, "(?<=[>])\s{2,}(?=[<])|(?<=[>])\s{2,}(?= )|(?<=&ndsp;)\s{2,}(?=[<])", [String].Empty)
'Remove comments from CSS
body = Regex.Replace(body, "/\*[\d\D]*?\*/", String.Empty)
Return body
End Function
サンプルホワイトスペースRemovelの機能のためにJS:
Private Function StripWhitespace(ByVal body As String) As String
Dim lines As String() = body.Split(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
Dim emptyLines As New StringBuilder()
For Each line As String In lines
Dim s As String = line.Trim()
If s.Length > 0 AndAlso Not s.StartsWith("//") Then
emptyLines.AppendLine(s.Trim())
End If
Next
body = emptyLines.ToString()
body = Regex.Replace(body, "^[\s]+|[ \f\r\t\v]+$", [String].Empty)
body = Regex.Replace(body, "([+-])\n\1", "$1 $1")
body = Regex.Replace(body, "([^+-][+-])\n", "$1")
body = Regex.Replace(body, "([^+]) ?(\+)", "$1$2")
body = Regex.Replace(body, "(\+) ?([^+])", "$1$2")
body = Regex.Replace(body, "([^-]) ?(\-)", "$1$2")
body = Regex.Replace(body, "(\-) ?([^-])", "$1$2")
body = Regex.Replace(body, "\n([{}()[\],<>/*%&|^!~?:=.;+-])", "$1")
body = Regex.Replace(body, "(\W(if|while|for)\([^{]*?\))\n", "$1")
body = Regex.Replace(body, "(\W(if|while|for)\([^{]*?\))((if|while|for)\([^{]*?\))\n", "$1$3")
body = Regex.Replace(body, "([;}]else)\n", "$1 ")
body = Regex.Replace(body, "(?<=[>])\s{2,}(?=[<])|(?<=[>])\s{2,}(?= )|(?<=&ndsp;)\s{2,}(?=[<])", [String].Empty)
Return body
End Function
ここ 圧縮にサンプル出力です。
Dim request As HttpRequest = context.Request
Dim response As HttpResponse = context.Response
Dim browserAcceptedEncoding As String = request.Headers("Accept-Encoding")
If Not String.IsNullOrEmpty(browserAcceptedEncoding) Then
browserAcceptedEncoding = browserAcceptedEncoding.ToLowerInvariant
If (browserAcceptedEncoding.Contains("gzip")) Then
response.AppendHeader("Content-encoding", "gzip")
response.Filter = New GZipStream(response.Filter, CompressionMode.Compress)
ElseIf (browserAcceptedEncoding.Contains("deflate")) Then
response.AppendHeader("Content-encoding", "deflate")
response.Filter = New DeflateStream(response.Filter, CompressionMode.Compress)
End If
End If
あなたはたぶん使用してブロックでのStreamReaderを包むこのプロジェクト - http://requestreduce.com/ – MatthewMartin
から対応するソースコードをチェックするかもしれません – DaveHogan