Ticket #2972 (closed feature: duplicate)

Opened 2 years ago

Last modified 2 years ago

Closure Compiler for OpenLayers 2.x

Reported by: jorix Owned by:
Priority: minor Milestone: 2.11 Release
Component: general Version: 2.10
Keywords: Cc:
State:

Description

Using the Closure Compiler can compress the code by 20% but also to find errors such as undefined variables. Undefined variables in JavaScript are a nightmare because they are global names.

I've embedded the Clousure Compiler in build/build.py selecting run parameters that do not generate too many warnings and not allow undefined variables.

See bugs: #2960 and #2971 which are detected with Clousure Compiler.

Attachments

CC-2972.patch Download (90.9 KB) - added by jorix 2 years ago.

Change History

Changed 2 years ago by jorix

Changed 2 years ago by jorix

  • state set to Needs Discussion

To attach the compiler has used some material from Closure Compiler (in "bulid/") and Closure Library (in "tools/")

The compiler is the only material that is not in the patch. "compiler.jar" must be downloaded to the folder "tools/closure-compiler/bin/" (without "compiler.jar" build.py work with jsmin)

NOTE: The patch only uses part of the power of the compiler, to obtain more benefit requires the use jsDoc tags and Closure Library, but this is hard work.

Changed 2 years ago by jorix

Features proposed in the patch for use of the Closure Compiler:

  • Use any OpenLayers configuration (*.cfg)
  • Show where there have been compilation errors: source file and line number (source code is used, not jsmin)
  • Maximize the checks but discard massive warnings (9676 warnings reported using "- warning_level VERBOSE"!)
  • Ensure the verification of undeclared variables (distractions make these variables as global)
  • Use externs to declare names of other products, commercial maps, Proj4js ...
  • Use SIMPLE_OPTIMIZATIONS, which compresses the code by 20% (ADVANCED_OPTIMIZATIONS requires a study of the pros and cons)
  • Launch the Java compiler from phython (discard the use of the Service API. To call the compiler uses material from "Closure Library")

Changed 2 years ago by jorix

WARNING: The compiler is the only material that is not in the patch. "compiler.jar" must be downloaded from:
 http://code.google.com/p/closure-compiler/downloads/detail?name=compiler-latest.zip&can=2&q=
to the folder: "tools/closure-compiler/bin/"

Missing line, add the line 53 in build.py:

                "--create_source_map", outputFilename.replace(".js","") + "-map",

to allow the use of the Closure Inspector.


The patch is a starting point, but it is fully operational.

Thanks for any questions, concerns or comments.

Changed 2 years ago by jorix

  • status changed from new to closed
  • state Needs Discussion deleted
  • resolution set to duplicate

See #3008

Note: See TracTickets for help on using tickets.