谷歌闭包编译器不返回已编译的代码?
在 Stack Overflow 的另一个问题中,我发现了一个非常有用的代码片段,用于将代码发送到 Google Closure 编译器,它可以很好地缩小 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
可能是什么原因?我很想知道。
In another question here at Stack Overflow, I came across a very helpful code snippet to send code to the Google Closure Compiler, which can minify JavaScript files pretty good.
The problem I'm facing however is that it returns no compiled code in cases I don't expect it to do so.
Code:
This works, i.e. returns minified code:
Dim script = "function test(name) {alert(name);}test('New user');"
This one, on the other hand, does not return anything. The statistics are sent, but no compiled data...:
Dim script = "function test(name) {alert(name);}"
Rest of the code which actually does the work:
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
What could be the casue at all? I'm curious to know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能使用 ADVANCED_OPTIMIZATIONS 设置?该函数可能已被删除,因为它已被定义,但从未使用过。
查看此页面:闭包编译器教程
Possibly using the ADVANCED_OPTIMIZATIONS setting? The function may have been stripped because it is defined, but never used.
check out this page: closure compiler tutorial