Closure compiler and bootstrap twitter

789 views
Skip to first unread message

Alex Objelean

unread,
Nov 29, 2011, 10:54:30 AM11/29/11
to closure-comp...@googlegroups.com
Hello,

there seems to be a problem after compressing the bootstrap-mobile.js from the bootstrap-twitter library with google closure compiler using simple or advanced options. Probably after compression the js is broken. You can reproduce this problem by compressing that file and using the compressed version in demo provided by bootstrap-twitter. You'll notice that the modal widget doesn't work with the compressed version of js file.

Any thoughts?

Thanks,
Alex

Chris Price

unread,
Nov 29, 2011, 10:58:46 AM11/29/11
to closure-comp...@googlegroups.com
Hi Alex,

By bootstrap-mobile.js do you mean bootstrap-modal.js? I got excited
there thinking that they'd brought out the new version in which
they've hinted at making responsive designs possible (i.e. usable on
mobile!) :)

Chris

John Lenz

unread,
Nov 29, 2011, 11:59:06 AM11/29/11
to closure-comp...@googlegroups.com
For simple mode, try compiling it with the compiler's "--debug" option?  That might provide a clue as to the failure.

Alex Objelean

unread,
Nov 29, 2011, 1:47:12 PM11/29/11
to closure-comp...@googlegroups.com
Yes, it is bootstrap-modal.js :D... not sure the mobile version is available. Sorry for misleading you..

Alex Objelean

unread,
Nov 29, 2011, 1:48:35 PM11/29/11
to closure-comp...@googlegroups.com
Actually the js is getting minimized, but the demo page doesn't work properly with the minimized version.

Thanks, 
Alex

Alan Leung

unread,
Nov 29, 2011, 2:14:08 PM11/29/11
to closure-comp...@googlegroups.com
Hey Alex:

Where is the demo?

bootstrap-modal.js seems to be pretty simple. Doesnt seem like it should break simple mode.

-Alan

Alex Objelean

unread,
Nov 30, 2011, 2:41:14 AM11/30/11
to closure-comp...@googlegroups.com
Go to this link: http://twitter.github.com/bootstrap/javascript.html#modal  and click Launch Modal button. When using the compressed version of bootstrap-modal.js, the modal window doesn't work as expected (for instance the close icon doesn't work).

Thanks,
Alex

Alex Objelean

unread,
Dec 8, 2011, 7:33:11 AM12/8/11
to closure-comp...@googlegroups.com
Hi Alan,

have you managed to reproduce the problem? 

Thanks,
Alex

Alan Leung

unread,
Dec 8, 2011, 8:57:26 PM12/8/11
to closure-comp...@googlegroups.com
Reproduced. Debugging....

Alan Leung

unread,
Dec 8, 2011, 10:49:19 PM12/8/11
to closure-comp...@googlegroups.com
Ah. Not the first time some code got bitten by this:

if (transition) {
that.$element[0].offsetWidth // force reflow
}

There are two occurrence of this. Closure compiler thinks these lines does nothing and removed it. We are looking into ways to annotated these type of getters that has sideeffect.

What you could do to get around this is:

window.blah = this.element[0].offsetWidet.

Not the most elegant solution but it works.

-Alan

John Lenz

unread,
Dec 9, 2011, 2:35:06 PM12/9/11
to closure-comp...@googlegroups.com

goog.reflect.sinkValue is the Closure Library work around.

sent from a mobile phone excuse the spelling ...

Alan Leung

unread,
Dec 9, 2011, 3:15:49 PM12/9/11
to closure-comp...@googlegroups.com
Ya. I don't know if they want to pull in Closure Lib just for that.

Nick Santos

unread,
Dec 9, 2011, 3:22:11 PM12/9/11
to closure-comp...@googlegroups.com
you can just copy the implementation of sinkValue and it will work fine.

function sinkValue(x) {
  return sinkValue[' '](x);
}
sinkValue[' '] = function(x) { return x; }

gboege

unread,
Apr 25, 2012, 5:28:17 AM4/25/12
to closure-comp...@googlegroups.com
Hi

I have just noticed, that not only the bootstrap-modal.js is affected. Also bootstrap-collapse.js and bootstrap-carousel.js don't work properly after simple or advanced compressing with the clusure compiler. Noticed the problem when adapting the bootstrap to the HTML5 Boilerplate Buildscript. My quick and dirty solution: Just mark the 3 files as *.min.js and these 3 files will additionally pass the compiler, but they will be concatenated. Some more bytes, due to not compressing these 3 files, but the workflow is stable with the supplied js-files without change the js-code.

gboege

Alan Leung

unread,
Apr 29, 2012, 8:55:07 PM4/29/12
to closure-comp...@googlegroups.com
Hi.

I am not sure what you are referring to. Can you be more specific if you think there is a bug in the compiler?

-Alan

John Lenz

unread,
Aug 6, 2012, 9:25:17 PM8/6/12
to closure-comp...@googlegroups.com
What version are you using, it looks like it is a named function when I look at github:

http://twitter.github.com/bootstrap/assets/js/bootstrap-modal.js

On Mon, Aug 6, 2012 at 5:49 AM, <dionysis....@gmail.com> wrote:
I found that there is a conflict with a callback name in function backdrop(callback) {} which in minimized form becomes b(b). One possible solution is to replace anonymous callback with a named function. So the line backdrop.call(this, function () { [...] }) becomes backdrop.call(this,  callback_show .call(this)).

As a conclusion Closure does not seem to work well with anonymous callbacks!

John Lenz

unread,
Aug 7, 2012, 2:59:02 PM8/7/12
to closure-comp...@googlegroups.com
To be clear, I looking for specific steps to reproduce this problem: "grap file from URL", "compile the file with SIMPLE on closure-compiler.appspot.com", "notice that 'backdrop' is renamed to 'b' and cause a conflict with X because of Y".  The snippets shown so far don't give enough content for us to fix any problem or explain any behavior.  

John Lenz

unread,
Aug 9, 2012, 3:19:25 PM8/9/12
to closure-comp...@googlegroups.com
Fantastic!

On Thu, Aug 9, 2012 at 12:11 PM, <dionysis....@gmail.com> wrote:
Ok John, at your example it works fine. I moved to the latest compiler.jar and it also works fine. Thanks.
Reply all
Reply to author
Forward
0 new messages