谷歌闭包编译器不返回已编译的代码?

发布于 2024-10-16 09:24:34 字数 1717 浏览 7 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安穩 2024-10-23 09:24:34

可能使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文