google-closure-compiler

Partially skip sections with Google Closure Compiler

醉酒当歌 提交于 2019-12-17 06:56:11
问题 I'm generating a javascript on the server like and would like to run Google Clousure Compiler to be ran on the php source code of the script. var jsvar = <?=$var ? true : false ?>; Just wandering if there is any way in telling the compiler to skip optimazation of ? Like a regexp skip: /<\?=.*?\?>/ Best regards, Niclas 回答1: I have found that my code is much easier to maintain when I separate my client-side JavaScript from my server-side logic. Now I write my scripts such that my server-side

difference between “void 0 ” and “undefined”

倾然丶 夕夏残阳落幕 提交于 2019-12-17 04:47:58
问题 I'm using "Closure Compiler", when compiling my scripts I spend the following: Before compiling: // ==ClosureCompiler== // @compilation_level SIMPLE_OPTIMIZATIONS // @output_file_name default.js // @formatting pretty_print,print_input_delimiter // ==/ClosureCompiler== var myObj1 = (function() { var undefined; //<----- declare undefined this.test = function(value, arg1) { var exp = 0; arg1 = arg1 == undefined ? true : arg1; //<----- use declare undefined exp = (arg1) ? value * 5 : value * 10;

How to distribute a library which uses Closure-library without including any of the actual Closure-library source?

我与影子孤独终老i 提交于 2019-12-13 05:24:34
问题 I've recently created a JavaScript library using Google's Closure Compiler: https://github.com/bvaughn/task-runner I intend for this library to be used by applications that also require the full Closure Library , and so I want the built version of my library (Task Runner) not to include a subset of Closure Library. If Task Runner includes a subset of Closure Library, and another application includes the full Closure Library, a race condition will exist between which loads Closure last (last

Minify JavaScript code containing Jinja2 expressions with the Closure Compiler

╄→尐↘猪︶ㄣ 提交于 2019-12-13 05:06:18
问题 I pass a JSON-encoded dictionary from Python 3 to Jinja2 template and assign it to a JavaScript variable. My template is as follows <script> var a = {{ json_dict }}; // is rendered as `var a = {"key": "value"};` </script> This works as expected, but I'd like to minify JavaScript code containing Jinja2 expressions using Closure Compiler, which currently throws predictable errors like JSC_PARSE_ERROR: Parse error. '}' expected at line 2 character 9 var a = {{ json_dict }}; What are my options?

Closure: --namespace Foo does not include Foo.Bar, and related issues

空扰寡人 提交于 2019-12-13 04:34:47
问题 I have a rather big library with a significant set of APIs that I need to expose. In fact, I'd like to expose the whole thing. There is a lot of namespacing going on, like: FooLibrary.Bar FooLibrary.Qux.Rumps FooLibrary.Qux.Scrooge .. Basically, what I would like to do is make sure that the user can access that whole namespace. I have had a whole bunch of trouble with this, and I'm totally new to closure, so I thought I'd ask for some input. First, I need closurebuilder.py to send the full

Function with eval won't make it through minification

…衆ロ難τιáo~ 提交于 2019-12-13 04:32:58
问题 Here is my weird function that let my users create their own javascript code function evalThisFunction(functionBody){ var func; eval("func = " + functionBody); return func; } But after minification with Closure Compiler (http://closure-compiler.appspot.com/), I get this result : function a(b){eval("func = "+b);} Do you see a way I can modify my weird function so it will still works after minification? 回答1: Yes, use the Function constructor: function evalThisFunction(functionBody){ return

Activate a combobox from a checkbox using google closure

五迷三道 提交于 2019-12-13 04:22:31
问题 I have a set of check boxes with Id's user1,user2 and so on and also set of combo boxes with Id's usersel1,usersel2 and so on in a dialog. When a check box is checked (say suppose with Id user1) then corresponding combo box must be activated(i.e combo box with Id usersel1). I have the following code and isn't working. How do i achieve this behavior? for(var g=0;g<userlist.length;g++) //userlist.length give no of users b2 = (goog.dom.getElement('usersel'+(g+1))); //gets combo box //listening

Forcing specification of a generic Closure type

坚强是说给别人听的谎言 提交于 2019-12-13 02:53:57
问题 Generally, if you fail to specify a generic type parameter in Closure, it won't raise an error. This is different than many other languages, including TypeScript. Closure will treat the type as an "unknown" type, which are usually ignored. (It's possible to set compiler flags to have it complain about unknown types, but these can only be set globally and often too noisy to really use.) I have a Closure class, Response<T> . I would like all Response instances to specify a type for <T> , not

Google Closure compiler not compressing string values?

房东的猫 提交于 2019-12-12 15:16:05
问题 Having something like this: (function ($, window, document, undefined) { 'use strict'; $.fn.demo = function (options) { var active = "active"; var section = ".bb-demo"; $(section).addClass(active); $(section).addClass(active); $(section).addClass(active); $(section).addClass(active); }; })(jQuery, window, document); Closure Simple mode results in 200 bytes : (function(a,b,c,d){a.fn.demo=function(b){a(".bb-demo").addClass("active");a(".bb-demo").addClass("active");a(".bb-demo").addClass(

Which tools does jQuery use to compress its source code

时光怂恿深爱的人放手 提交于 2019-12-12 10:05:10
问题 Which tools does jQuery use to compress its source code in version 1.6.2? 回答1: It uses UglifyJS. Previously (until 1.4) they used Packer. https://github.com/jquery/jquery/blob/master/Makefile#L9 回答2: I'm not sure, but I find this (minifyjavascript.com) useful, dunno if it helps. 来源: https://stackoverflow.com/questions/6608079/which-tools-does-jquery-use-to-compress-its-source-code