2011-02-09 104 views
1

在Stack Overflow的另一個問題中,我遇到了一個非常有用的代碼片段,可以將代碼發送到Google Closure編譯器,該代碼片段可以很好地縮小JavaScript文件。Google Closure編譯器不會返回任何編譯代碼?

然而,我面臨的問題是,它不會返回任何編譯的代碼,我不希望它這樣做。

代碼:

這工作,即返回精縮代碼:

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呢?我很想知道。

回答

2

可能使用ADVANCED_OPTIMIZATIONS設置?該功能可能已被剝離,因爲它已定義,但從未使用。

查看此頁面:closure compiler tutorial

+0

我測試一樣,用先進的優化和消除警報,並預期它去除功能。 – kmfk 2011-02-09 18:57:39