question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

single function stops working after ADVANCED_OPTIMISATION

See original GitHub issue

I tried optimize my simple code which uses jQuery. I included jQuery’s code and close it in one function with my code, to avoid any external dependencies.

Code works fine in SIMPLE_OPTIMISATION mode, and gives: ‘Uncaught TypeError: $ is not a function’ in ADVANCED_OPTIMISATION

(function(){

//jQuery without any modification included here. Omited.
/*! jQuery v1.11.1 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */

  /*this line works in SIMPLE_OPTIMISATION mode, and gives:
  'Uncaught TypeError: $ is not a function' in ADVANCED_OPTIMISATION */
  $(window);
})()

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Dominator008commented, Aug 10, 2016

It’s likely that the jQuery code you included does not explicitly export the $ symbol, so the compiler will remove it. AFAIK the jQuery code itself is not compatible with ADVANCED_OPTIMIZATION, so a better way would be compiling just your application with the jQuery externs file (https://github.com/google/closure-compiler/blob/master/contrib/externs/jquery-1.9.js), and then bundling it with a minified jQuery code. The externs file is named jquery-1.9.js but should work under 1.11 in most cases.

0reactions
Dominator008commented, Aug 10, 2016

Most random code are compatible with SIMPLE _OPTIMIZATIONS, making them compatible WITH ADVANCED is a non-goal for the compiler 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

2.7. Mathematical optimization: finding minima of functions
Many optimization methods rely on gradients of the objective function. If the gradient function is not given, they are computed numerically, which induces ......
Read more >
5.8 Optimization Problems
Guideline for Solving Optimization Problems. · Identify what is to be maximized or minimized and what the constraints are. · Draw a diagram...
Read more >
24 Improving performance | Advanced R - Hadley Wickham
After several hours work, I was able to isolate the minimal code shown above. This is a very useful technique. Most base R...
Read more >
Optimize Options (Using the GNU Compiler Collection (GCC))
This is the default when not optimizing. Single functions can be exempted from inlining by marking them with the noinline attribute. -finline-small-functions.
Read more >
Understanding the Restrictions Imposed by the Closure ...
All Compiler optimization levels remove comments, so code that relies on specially formatted comments does not work with the Compiler.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found