1

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.

4

1 回答 1

2

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

于 2011-02-09T18:52:22.800 回答