在Stack Overflow的另一个问题中,我遇到了一个非常有用的代码片段,可以将代码发送到Google Closure Compiler,它可以很好地缩小JavaScript文件。
然而,我面临的问题是,在我不希望它这样做的情况下,它不会返回编译代码。
代码:
这有效,即返回缩小的代码:
Dim script = "function test(name) {alert(name);}test('New user');"
另一方面,这个没有返回任何东西。发送统计信息,但没有编译数据......:
Dim script = "function test(name) {alert(name);}"
实际完成工作的其余代码:
Dim Data = String.Format(ClosureWebServicePOSTData, HttpUtility.UrlEncode(script))
_Result = New StringBuilder
_HttpWebRequest = DirectCast(WebRequest.Create(ClosureWebServiceURL), HttpWebRequest)
_HttpWebRequest.Method = "POST"
_HttpWebRequest.ContentType = "application/x-www-form-urlencoded"
'//Set the content length to the length of the data. This might need to change if you're using characters that take more than 256 bytes
_HttpWebRequest.ContentLength = Data.Length
'//Write the request stream
Using SW As New StreamWriter(_HttpWebRequest.GetRequestStream())
SW.Write(Data)
End Using
Dim response As WebResponse = _HttpWebRequest.GetResponse()
Using responseStream As Stream = response.GetResponseStream
Dim encoding As Encoding = System.Text.Encoding.GetEncoding("utf-8")
Using readStream As New StreamReader(responseStream, encoding)
Dim read(256) As Char
Dim count As Integer = readStream.Read(read, 0, 256)
While count > 0
Dim str As New String(read, 0, count)
_Result.Append(str)
count = readStream.Read(read, 0, 256)
End While
End Using
End Using
什么可能是casue?我很想知道。
答案 0 :(得分:2)
可能使用ADVANCED_OPTIMIZATIONS设置?该函数可能已被剥离,因为它已定义,但从未使用过。