closure rest api down?

44 views
Skip to first unread message

Dean Mao

unread,
Apr 20, 2011, 7:22:27 PM4/20/11
to Closure Compiler Discuss
This is a simplified version of what is running in our production app:

require 'net/http'
javascript = "window.asdf = function () {console.log('hello');}"
res = Net::HTTP.post_form(URI.parse('http://closure-
compiler.appspot.com/compile'), {
'js_code' => javascript,
'compilation_level' =>
'SIMPLE_OPTIMIZATIONS',
'output_format' => 'text',
'output_info' => 'compiled_code'
})
p res
p res.body

Right now res.body is a newline character -- essentially it is
returning nothing. It was working fine yesterday however.

Nick Santos

unread,
Apr 20, 2011, 7:28:48 PM4/20/11
to closure-comp...@googlegroups.com
Are you sending a request to the closure-compiler web service on every
request of your production app?

If this is what's you're doing, it would not surprise me if DDOS
protection kicked in and blocked you.

Dean Mao

unread,
Apr 20, 2011, 7:53:41 PM4/20/11
to Closure Compiler Discuss
No, we cache it locally. We only use it to compress the javascript if
we detect that the sha1 hash of the javascript content has changed.
If the content is different, then we run it through the closure
compiler rest api, then save the contents to a file locally.

However, as a side note, I did discover something interesting. This
code causes the closure compiler to bomb, but is technically legal
javascript:

Some code had this javascript:

if (settings.class) {
anchor.attr('class', settings.class);
}

When running through closure rest api, it returns an empty string but
does not return a warning or error message. Is this a side effect of
using Java as compression here? class might be reserved in Java, but
should be legal in javascript.

Here's an example. The code below works fine for testCode1, but fails
on testCode2. The only difference between the content is that
testCode2 has "settings.class", instead of "settings.clas". The
javascript is technically valid, why would closure fail for testCode2?

require 'net/http'
testCode1 = "function test() {if (settings.clas)
{console.log('hello')}}"
testCode2 = "function test() {if (settings.class)
{console.log('hello')}}"
res = Net::HTTP.post_form(URI.parse('http://closure-
compiler.appspot.com/compile'), {
'js_code' => testCode2,
'compilation_level' =>
'SIMPLE_OPTIMIZATIONS',
'output_format' => 'text',
'output_info' => 'compiled_code'
})
p res.body

Joseph Schorr (יוסף שור)

unread,
Apr 20, 2011, 8:02:09 PM4/20/11
to closure-comp...@googlegroups.com
'class' is technically a reserved word in the ECMAScript spec, so the Closure compiler could be parsing it as such (and therefore, failing).

Dean Mao

unread,
Apr 20, 2011, 8:12:34 PM4/20/11
to Closure Compiler Discuss
Shouldn't it produce an error and tell me then? If I use
output_format as 'xml', and output_info as 'warnings', it doesn't
return anything that would tell me the problem. It just dies
silently.


On Apr 20, 5:02 pm, Joseph Schorr (יוסף שור) <jsch...@google.com>
wrote:
> > compiler.appspot.com/compile' <http://compiler.appspot.com/compile%27>), {
> >                             'js_code' => testCode2,
> >                             'compilation_level' =>
> > 'SIMPLE_OPTIMIZATIONS',
> >                            'output_format' => 'text',
> >                            'output_info' => 'compiled_code'
> >                          })
> > p res.body
>
> > On Apr 20, 4:28 pm, Nick Santos <nicksan...@google.com> wrote:
> > > Are you sending a request to the closure-compiler web service on every
> > > request of your production app?
>
> > > If this is what's you're doing, it would not surprise me if DDOS
> > > protection kicked in and blocked you.
>
> > > On Wed, Apr 20, 2011 at 7:22 PM, Dean Mao <dean...@gmail.com> wrote:
> > > > This is a simplified version of what is running in our production app:
>
> > > > require 'net/http'
> > > > javascript = "window.asdf = function () {console.log('hello');}"
> > > > res = Net::HTTP.post_form(URI.parse('http://closure-
> > > > compiler.appspot.com/compile' <http://compiler.appspot.com/compile%27>),

Alan Leung

unread,
Apr 20, 2011, 8:19:08 PM4/20/11
to closure-comp...@googlegroups.com
http://code.google.com/closure/compiler/docs/api-ref.html

You'd need output_info=error and warning as well.

-Alan
Reply all
Reply to author
Forward
0 new messages