Test for Google Closure Library

When I search for performance of Javascript libraries, I get many sites showing performance comparisons between the following popular libraries

  • jQuery (pretty slow)
  • Prototype (very slow in IE)
  • Dojo (fastest for DOM)
  • ExtJs (medium)
  • Micro JS (slow but normal)

But in any of the standards Google Closure Library is NOT included. Isn’t it like any other standard library as it is said to be a procedural style library.

I need some performance tests of the Closure library. And I would like to consult with "Is switching to the Closure library good when using dojo at the beginner stage and jQuery at some intermediate stage"

Google messaging uses the closure library in all of its applications, such as Gmail, etc. Performance is very good. Is it because of the library? Can an intermediate javaScript encoder that can write OO code in JS use the Closure library at a very high level, or is it advisable to continue to use DOJO.

+6
source share
3 answers

In the closing library

The Closure library is pretty close to Dojo in style - in fact, when it was first developed, the authors took inspiration from Dojo.

However, the speed and power of the Closure library was obtained from the Closure compiler, which pretty much optimizes the JavaScript program to remove all bottlenecks (for example, moving namespace chains).

I personally don’t like it, since it detracts from the beauty of the constructions of the Dojo class (just to satisfy the compiler), and all those goog.kitchen.sink.getMeACupOfTeaSoICanRelax() spaces long namespaces write (and read) JavaScript programs is a goog.kitchen.sink.getMeACupOfTeaSoICanRelax() pain that long namespaces are fully optimized by the compiler does not make it quite (for me) excessive use, because you can.

Furthermore, his obsession with trying to make JavaScript programs look as large as OOP (possibly because Google has a lot of Java programmers) means it is overly dependent on OOP concepts such as getters and seters properties, and avoiding many useful (and unique) ones JavaScript features like mixin's. If you are programming Java for JavaScript, you will be at home using the Closure library. This does not make it a little elegant.

However, it does offer industrial strength , which is solid , since Google built HUGE sites with it. This is what (in my personal opinion) is solid and works well, but looks ugly.

However, Dojo is also solid, but more volatile, as it is an open source development project. You decide if you want to switch.

In the Closure and Dojo compiler

Actually, you can also use Dojo with the Closure compiler in advanced mode. See this link for a description of how to do this. Based on my own tests, the program compiled by the Closure compiler is usually 25% smaller than the mini versions (due to elimination of dead code) and works 20-30% faster for simple pages and more for large pages.

About the speed of libraries in general

Other libraries have their own characteristics and quirks, as well as ease of use, flexibility and power in balance. For example, jQuery creates many jQuery objects in its path and has performance limitations, especially in older browsers. However, modern browsers, especially. Google Chrome actually does the optimization, so performance with jQuery is minimal.

You really need to ask yourself why you need JavaScript fast. Most modern browsers are already pretty fast, so this is really not very important for choosing a library. It’s better to choose your library based on whether it suits you or not (and the task you are at hand right now) instead of whether it works 10 ms faster in the browser.

If you are writing a website for mobile devices or, for example, playing HTML5, you may need to compress the last drop of productivity (in games) and / or save as many resources as possible (on mobile devices). In such cases, I find that using Dojo and then compiling with the Closure Compiler gives one of the best combinations for such scenarios.

+7
source

It would be nice to support this with some data. There are lies, statistics and benchmarks. You may, for example, ask yourself why the infrastructure x is slower than the structure y. In general, however, the tests do not reflect the real-world scenario and end in fun, but are useless. I have been working with jQuery for several years, and I have not encountered situations where it is slow, or that this has affected usability.

I'm your code is too slow, and you need to optimize it. Then you can check, profile and debug sweet jesus from this code. Things like gmail probably had that kind of treatment. Therefore, gmail is probably not fast due to closure, but fast due to intelligent programming.

If you are afraid of slow code, you can learn common javascript optimization methods and you will be a happy camper with any infrastructure.

edit: when closing The choice of closing can have several advantages when you build large and complex ones: there are some good bandwidth optimization tools, tools for managing more complex applications. There is a good guide to writing proper code and tools to verify that you followed these recommendations (closing lint, quite interesting). There is a good template system (it may not improve your performance as such) and dependency management material. If you want to integrate these tools or build on them, I would say go for it, otherwise you may be calm and be pleased with your choice for dojo.

+1
source

using dojo at the initial stage and jQuery at some intermediate stage

This is not so for you. dojo is much more advanced than jQuery. JQuery itself is for beginners.

Can an intermediate javaScript encoder that can write OO code in JS use the Closure library at a very high level, or is it advisable to continue to use DOJO.

Any library will work. Spend a few hours playing with the closure of Google and find out how you find it. I doubt that there is a big difference besides simple simple integration with Google libraries such as Google charts.

+1
source

Source: https://habr.com/ru/post/890952/


All Articles