SlideShare a Scribd company logo
Closure Compiler
By Prasad K
Introduction
Closure Compiler is an open source tool developed by Google engineers to
compile javascript code to better javascript code. It makes Javascript compact
and efficient.
It parses your javascript, removes dead code, rewrites everything and minimizes
what is left so that it downloads and runs quickly, and also reduces your
bandwidth needs.
It also checks syntax, variable references, and types, and warns about common
javascript pitfalls.
How to use?
We can make use of this tool in different ways as per our
convenience.
Closure Compiler comes as a
1. Web Interface
2. Restful API
3. Java Application
Easiest way to try out this compiler service is by using their UI
http://closure-compiler.appspot.com/home
Lets try optimizing a small snippet of code to get familiar with it.
Open the above link in browser, and enter the following code and click Compile button with default options chosen.
function helloWorld(message) {
alert(message);
}
helloWorld("Hello, Google Closure Compiler! Thank you so much!");
You will see the compiled code as
function helloWorld(a){alert(a)}helloWorld("Hello, Google Closure Compiler! Thank you so
much!");
The default optimization used here was Simple Optimization. In this example, local variables names are modified to short
names to reduce the size of your code and whitespaces have been removed. I will explain you more about these
optimization techniques in the next section.
Web Interface
You can also optimize one or more javascript files using this UI by adding urls in the form.
1. Copy and Paste your javascript file link in Add a URL box and click Add button.
2. You can add multiple js files in the same way and click Compile button.
3. You will see the compiled code (compiled using Simple Optimization technique) on the right hand side.
You can copy this code and paste in a single file to use it in your project.
Closure compiler UI is easy to start with and good for few files. But if you want to use it for a large
project and automate this compilation process for js files in your project, you will have to use their API.
They have a simple web-based API which takes a few parameters to customize this compilation
process.
Request URL
http://closure-compiler.appspot.com/compile
Request Parameters
js_code or code_url
The js_code parameter must be a string that contains JavaScript, such as alert('hello'). The code_url parameter must
contain the URL of a JavaScript .js file. You must include at least one of these parameters, and you can include both.
And you can send multiple
compilation_level
The value of this parameter indicates the degree of compression and optimization to apply to your JavaScript. There are
three possible compilation levels:
WHITESPACE_ONLY, SIMPLE_OPTIMIZATIONS, and ADVANCED_OPTIMIZATIONS.
The compilation_level parameter defaults to SIMPLE_OPTIMIZATIONS.
Restful API
output_info
The value of this parameter indicates the kind of information that you want from the compiler. There are four possible kinds of
output: compiled_code, warnings, errors, and statistics.
output_format
The format for the Closure Compiler service's output.
There are three possible output formats: text, json, or xml. The output_format parameter defaults to text.
You can send a post request to the API url by sending the above specified request parameters and the response of the request will
be the compiled code which you can save into a file and use in your project.
Closure Compiler comes as a java application which you can download and use it from command line.
1. Download the latest zip file from
http://closure-compiler.googlecode.com/files/compiler-latest.zip
And save it in a directory.
2. Extract compiler.jar file from it and save it in the same folder.
3. Create a js file and compile it by using the following command
java -jar compiler.jar --js hello.js --js_output_file hello-compiled.js
This command will compile hello.js and store the compiled code in hello-compiled.js file.
So, these are the different ways we can use closure compiler. Using Rest api
among the three will be the better option to smoothen our development process.
Java Application
Closure compiler provides three levels of compilation. You
should choose one of them while compiling your code.
1. WHITESPACE_ONLY
2. SIMPLE_OPTIMIZATIONS
3. ADVACNED_OPTIMIZATIONS
Compilation Levels
This compilation level removes comments from your code and also removes line
breaks, unnecessary spaces, and other whitespace.
Optimizing the following snippet of code:
function helloWorld(message) {
alert(message);
}
helloWorld("Hello, Google Closure Compiler! Thank you so much!");
with whitespace_only gives the following code
function helloWorld(message){alert(message)}helloWorld("Hello, Google Closure Compiler!
Thank you so much!");
The output JavaScript is functionally identical to the source JavaScript.
It provides the least compression of the three levels.
1. WHITESPACE_ONLY
This compilation level performs the same operations of WHITESPACE_ONLY,
but it also does more optimization by renaming local variables in functions and
modifying expressions.
Optimizing the following snippet of code:
function helloWorld(message) {
alert(message);
}
helloWorld("Hello, Google Closure Compiler! Thank you so much!");
with SIMPLE_OPTIMZATIONS gives the following code
function helloWorld(a){alert(a)}helloWorld("Hello, Google Closure Compiler! Thank you so
much!");
As this level renames only symbols that are local to functions, it does not
interfere with the interaction between the compiled JavaScript and other
JavaScript.
2. SIMPLE_OPTIMIZATIONS
Compilation with simple_optimzations always preserves the functionality of
syntactically valid JavaScript, provided that the code does not access local
variables using string names (by using eval() statements, for example).
SIMPLE_OPTIMIZATIONS is the default compilation level.
This compilation level performs the same transformations as
SIMPLE_OPTIMZATIONS, but adds a variety of more aggressive global
transformations to achieve the highest compression of all three levels.
This level compresses JavaScript well beyond what is possible with other tools.
Optimizing the following snippet of code:
function helloWorld(message) {
alert(message);
}
helloWorld("Hello, Google Closure Compiler! Thank you so much!");
with ADVANCED_OPTIMZATIONS gives the following code
alert("Hello, Google Closure Compiler! Thank you so much!");
Here the function call is replaced with the body of the function and removed the
function definition.
3. ADVANCED_OPTIMIZATIONS
To enable this extreme compression, ADVANCED_OPTIMIZATIONS makes
strong assumptions about the compiled code. If your code does not conform to
those assumptions, ADVANCED_OPTIMIZATIONS will produce code that does
not run.
The ADVANCED_OPTIMIZATIONS transformations include:
1. more aggressive renaming:
Renames global variables, function names and properties along with local
variables and parameters.
2. dead code removal:
Removes any unused functions or code.
3. global inlining:
Replaces some function calls with the body of the function.
Thank You
Prasad Kancharla,
Lead Software Developer
Riktam Technology Consulting Pvt. Ltd.,
Tel.+91 9848558696 (India)
http://www.riktamtech.com
http://prasadkancharla.blogspot.in/
http://labs.riktamtech.com
https://developers.google.com/closure/compiler/
See More
References
https://developers.google.com/closure/compiler/docs/limitations
https://developers.google.com/closure/compiler/docs/api-tutorial3
https://developers.google.com/closure/compiler/docs/js-for-compiler

More Related Content

What's hot

Design Thinking and Business Model Innovation at SAP - From Efficiency to Inn...
Design Thinking and Business Model Innovation at SAP - From Efficiency to Inn...Design Thinking and Business Model Innovation at SAP - From Efficiency to Inn...
Design Thinking and Business Model Innovation at SAP - From Efficiency to Inn...
Tobias Schimmer
 
How to build Micro Frontends with @angular/elements
How to build Micro Frontends with @angular/elementsHow to build Micro Frontends with @angular/elements
How to build Micro Frontends with @angular/elements
MarcellKiss7
 
La Duck Conf : "Event driven : est-ce que je suis prêt ?"
La Duck Conf : "Event driven : est-ce que je suis prêt ?"La Duck Conf : "Event driven : est-ce que je suis prêt ?"
La Duck Conf : "Event driven : est-ce que je suis prêt ?"
OCTO Technology
 
Benchmarking Agile Teams
Benchmarking Agile TeamsBenchmarking Agile Teams
Benchmarking Agile Teams
Christoph Mathis
 
Mikrofrontend a Module Federation
Mikrofrontend a Module FederationMikrofrontend a Module Federation
Mikrofrontend a Module Federation
The Software House
 
¿Qué es docker?
¿Qué es docker?¿Qué es docker?
¿Qué es docker?
Diego Gabriel Calbo Elizondo
 
RabbitMQ & Kafka
RabbitMQ & KafkaRabbitMQ & Kafka
RabbitMQ & Kafka
VMware Tanzu
 
ITKonekt 2023: The Busy Platform Engineers Guide to API Gateways
ITKonekt 2023: The Busy Platform Engineers Guide to API GatewaysITKonekt 2023: The Busy Platform Engineers Guide to API Gateways
ITKonekt 2023: The Busy Platform Engineers Guide to API Gateways
Daniel Bryant
 
Easy enterprise application integration with RabbitMQ and AMQP
Easy enterprise application integration with RabbitMQ and AMQPEasy enterprise application integration with RabbitMQ and AMQP
Easy enterprise application integration with RabbitMQ and AMQP
Rabbit MQ
 
git, 이해부터 활용까지
git, 이해부터 활용까지git, 이해부터 활용까지
git, 이해부터 활용까지
jylee1229
 
Docker Basics
Docker BasicsDocker Basics
Docker Basics
Eueung Mulyana
 
Top 50 MuleSoft interview questions
Top 50 MuleSoft interview questionsTop 50 MuleSoft interview questions
Top 50 MuleSoft interview questions
techievarsity
 
Micro Frontends: Rompiendo el monolito en las aplicaciones Web
Micro Frontends: Rompiendo el monolito en las aplicaciones WebMicro Frontends: Rompiendo el monolito en las aplicaciones Web
Micro Frontends: Rompiendo el monolito en las aplicaciones Web
Belatrix Software
 
Inside GitHub
Inside GitHubInside GitHub
Inside GitHub
err
 
Micro-frontend
Micro-frontendMicro-frontend
Software Architectures, Week 1 - Monolithic Architectures
Software Architectures, Week 1 - Monolithic ArchitecturesSoftware Architectures, Week 1 - Monolithic Architectures
Software Architectures, Week 1 - Monolithic ArchitecturesAngelos Kapsimanis
 
Developer Experience (DX) as a Fitness Function for Platform Teams
Developer Experience (DX) as a Fitness Function for Platform TeamsDeveloper Experience (DX) as a Fitness Function for Platform Teams
Developer Experience (DX) as a Fitness Function for Platform Teams
Andy Marks
 
Implementing Exactly-once Delivery and Escaping Kafka Rebalance Storms with Y...
Implementing Exactly-once Delivery and Escaping Kafka Rebalance Storms with Y...Implementing Exactly-once Delivery and Escaping Kafka Rebalance Storms with Y...
Implementing Exactly-once Delivery and Escaping Kafka Rebalance Storms with Y...
HostedbyConfluent
 
Micro Frontends Architecture - Jitendra kumawat (Guavus)
Micro Frontends Architecture - Jitendra kumawat (Guavus)Micro Frontends Architecture - Jitendra kumawat (Guavus)
Micro Frontends Architecture - Jitendra kumawat (Guavus)
Tech Triveni
 
Error Handling in Mulesoft
Error Handling in MulesoftError Handling in Mulesoft
Error Handling in Mulesoft
Amit Singh
 

What's hot (20)

Design Thinking and Business Model Innovation at SAP - From Efficiency to Inn...
Design Thinking and Business Model Innovation at SAP - From Efficiency to Inn...Design Thinking and Business Model Innovation at SAP - From Efficiency to Inn...
Design Thinking and Business Model Innovation at SAP - From Efficiency to Inn...
 
How to build Micro Frontends with @angular/elements
How to build Micro Frontends with @angular/elementsHow to build Micro Frontends with @angular/elements
How to build Micro Frontends with @angular/elements
 
La Duck Conf : "Event driven : est-ce que je suis prêt ?"
La Duck Conf : "Event driven : est-ce que je suis prêt ?"La Duck Conf : "Event driven : est-ce que je suis prêt ?"
La Duck Conf : "Event driven : est-ce que je suis prêt ?"
 
Benchmarking Agile Teams
Benchmarking Agile TeamsBenchmarking Agile Teams
Benchmarking Agile Teams
 
Mikrofrontend a Module Federation
Mikrofrontend a Module FederationMikrofrontend a Module Federation
Mikrofrontend a Module Federation
 
¿Qué es docker?
¿Qué es docker?¿Qué es docker?
¿Qué es docker?
 
RabbitMQ & Kafka
RabbitMQ & KafkaRabbitMQ & Kafka
RabbitMQ & Kafka
 
ITKonekt 2023: The Busy Platform Engineers Guide to API Gateways
ITKonekt 2023: The Busy Platform Engineers Guide to API GatewaysITKonekt 2023: The Busy Platform Engineers Guide to API Gateways
ITKonekt 2023: The Busy Platform Engineers Guide to API Gateways
 
Easy enterprise application integration with RabbitMQ and AMQP
Easy enterprise application integration with RabbitMQ and AMQPEasy enterprise application integration with RabbitMQ and AMQP
Easy enterprise application integration with RabbitMQ and AMQP
 
git, 이해부터 활용까지
git, 이해부터 활용까지git, 이해부터 활용까지
git, 이해부터 활용까지
 
Docker Basics
Docker BasicsDocker Basics
Docker Basics
 
Top 50 MuleSoft interview questions
Top 50 MuleSoft interview questionsTop 50 MuleSoft interview questions
Top 50 MuleSoft interview questions
 
Micro Frontends: Rompiendo el monolito en las aplicaciones Web
Micro Frontends: Rompiendo el monolito en las aplicaciones WebMicro Frontends: Rompiendo el monolito en las aplicaciones Web
Micro Frontends: Rompiendo el monolito en las aplicaciones Web
 
Inside GitHub
Inside GitHubInside GitHub
Inside GitHub
 
Micro-frontend
Micro-frontendMicro-frontend
Micro-frontend
 
Software Architectures, Week 1 - Monolithic Architectures
Software Architectures, Week 1 - Monolithic ArchitecturesSoftware Architectures, Week 1 - Monolithic Architectures
Software Architectures, Week 1 - Monolithic Architectures
 
Developer Experience (DX) as a Fitness Function for Platform Teams
Developer Experience (DX) as a Fitness Function for Platform TeamsDeveloper Experience (DX) as a Fitness Function for Platform Teams
Developer Experience (DX) as a Fitness Function for Platform Teams
 
Implementing Exactly-once Delivery and Escaping Kafka Rebalance Storms with Y...
Implementing Exactly-once Delivery and Escaping Kafka Rebalance Storms with Y...Implementing Exactly-once Delivery and Escaping Kafka Rebalance Storms with Y...
Implementing Exactly-once Delivery and Escaping Kafka Rebalance Storms with Y...
 
Micro Frontends Architecture - Jitendra kumawat (Guavus)
Micro Frontends Architecture - Jitendra kumawat (Guavus)Micro Frontends Architecture - Jitendra kumawat (Guavus)
Micro Frontends Architecture - Jitendra kumawat (Guavus)
 
Error Handling in Mulesoft
Error Handling in MulesoftError Handling in Mulesoft
Error Handling in Mulesoft
 

Similar to Google closure compiler

Java performance tuning
Java performance tuningJava performance tuning
Java performance tuning
Jerry Kurian
 
Codename one
Codename oneCodename one
Sprouting into the world of Elm
Sprouting into the world of ElmSprouting into the world of Elm
Sprouting into the world of Elm
Mike Onslow
 
JavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript HereJavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript Here
Laurence Svekis ✔
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to Java
SMIJava
 
Using galen framework for automated cross browser layout testing
Using galen framework for automated cross browser layout testingUsing galen framework for automated cross browser layout testing
Using galen framework for automated cross browser layout testing
Sarah Elson
 
Switch case looping
Switch case loopingSwitch case looping
Switch case looping
Cherimay Batallones
 
Angular JS in 2017
Angular JS in 2017Angular JS in 2017
Angular JS in 2017
Ayush Sharma
 
Android develop guideline
Android develop guidelineAndroid develop guideline
Android develop guideline
Kan-Han (John) Lu
 
Class notes(week 10) on applet programming
Class notes(week 10) on applet programmingClass notes(week 10) on applet programming
Class notes(week 10) on applet programming
Kuntal Bhowmick
 
Java lab1 manual
Java lab1 manualJava lab1 manual
Java lab1 manual
nahalomar
 
Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJSTroy Miles
 
3. Java Script
3. Java Script3. Java Script
3. Java Script
Jalpesh Vasa
 
React Basic and Advance || React Basic
React Basic and Advance   || React BasicReact Basic and Advance   || React Basic
React Basic and Advance || React Basic
rafaqathussainc077
 
AngularJS Beginner Day One
AngularJS Beginner Day OneAngularJS Beginner Day One
AngularJS Beginner Day One
Troy Miles
 
Closure Library: Build Complex JavaScript Applications
Closure Library: Build Complex JavaScript ApplicationsClosure Library: Build Complex JavaScript Applications
Closure Library: Build Complex JavaScript Applications
devbilt
 
Swift 2.0: Apple’s Advanced Programming Platform for Developers
Swift 2.0: Apple’s Advanced Programming Platform for DevelopersSwift 2.0: Apple’s Advanced Programming Platform for Developers
Swift 2.0: Apple’s Advanced Programming Platform for Developers
Azilen Technologies Pvt. Ltd.
 
Installing the java sdk
Installing the java sdkInstalling the java sdk
Installing the java sdk
Kennedy Kiprono
 

Similar to Google closure compiler (20)

Java performance tuning
Java performance tuningJava performance tuning
Java performance tuning
 
Codename one
Codename oneCodename one
Codename one
 
Sprouting into the world of Elm
Sprouting into the world of ElmSprouting into the world of Elm
Sprouting into the world of Elm
 
JavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript HereJavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript Here
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to Java
 
Using galen framework for automated cross browser layout testing
Using galen framework for automated cross browser layout testingUsing galen framework for automated cross browser layout testing
Using galen framework for automated cross browser layout testing
 
Switch case looping
Switch case loopingSwitch case looping
Switch case looping
 
Adobe Flex4
Adobe Flex4 Adobe Flex4
Adobe Flex4
 
Angular JS in 2017
Angular JS in 2017Angular JS in 2017
Angular JS in 2017
 
Android develop guideline
Android develop guidelineAndroid develop guideline
Android develop guideline
 
Class notes(week 10) on applet programming
Class notes(week 10) on applet programmingClass notes(week 10) on applet programming
Class notes(week 10) on applet programming
 
Java lab1 manual
Java lab1 manualJava lab1 manual
Java lab1 manual
 
Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJS
 
3. Java Script
3. Java Script3. Java Script
3. Java Script
 
Javascript tutorial
Javascript tutorialJavascript tutorial
Javascript tutorial
 
React Basic and Advance || React Basic
React Basic and Advance   || React BasicReact Basic and Advance   || React Basic
React Basic and Advance || React Basic
 
AngularJS Beginner Day One
AngularJS Beginner Day OneAngularJS Beginner Day One
AngularJS Beginner Day One
 
Closure Library: Build Complex JavaScript Applications
Closure Library: Build Complex JavaScript ApplicationsClosure Library: Build Complex JavaScript Applications
Closure Library: Build Complex JavaScript Applications
 
Swift 2.0: Apple’s Advanced Programming Platform for Developers
Swift 2.0: Apple’s Advanced Programming Platform for DevelopersSwift 2.0: Apple’s Advanced Programming Platform for Developers
Swift 2.0: Apple’s Advanced Programming Platform for Developers
 
Installing the java sdk
Installing the java sdkInstalling the java sdk
Installing the java sdk
 

Recently uploaded

In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
QuickwayInfoSystems3
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
Roshan Dwivedi
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Yara Milbes
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 

Recently uploaded (20)

In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 

Google closure compiler

  • 2. Introduction Closure Compiler is an open source tool developed by Google engineers to compile javascript code to better javascript code. It makes Javascript compact and efficient. It parses your javascript, removes dead code, rewrites everything and minimizes what is left so that it downloads and runs quickly, and also reduces your bandwidth needs. It also checks syntax, variable references, and types, and warns about common javascript pitfalls.
  • 3. How to use? We can make use of this tool in different ways as per our convenience. Closure Compiler comes as a 1. Web Interface 2. Restful API 3. Java Application
  • 4. Easiest way to try out this compiler service is by using their UI http://closure-compiler.appspot.com/home Lets try optimizing a small snippet of code to get familiar with it. Open the above link in browser, and enter the following code and click Compile button with default options chosen. function helloWorld(message) { alert(message); } helloWorld("Hello, Google Closure Compiler! Thank you so much!"); You will see the compiled code as function helloWorld(a){alert(a)}helloWorld("Hello, Google Closure Compiler! Thank you so much!"); The default optimization used here was Simple Optimization. In this example, local variables names are modified to short names to reduce the size of your code and whitespaces have been removed. I will explain you more about these optimization techniques in the next section. Web Interface
  • 5. You can also optimize one or more javascript files using this UI by adding urls in the form. 1. Copy and Paste your javascript file link in Add a URL box and click Add button. 2. You can add multiple js files in the same way and click Compile button. 3. You will see the compiled code (compiled using Simple Optimization technique) on the right hand side. You can copy this code and paste in a single file to use it in your project.
  • 6. Closure compiler UI is easy to start with and good for few files. But if you want to use it for a large project and automate this compilation process for js files in your project, you will have to use their API. They have a simple web-based API which takes a few parameters to customize this compilation process. Request URL http://closure-compiler.appspot.com/compile Request Parameters js_code or code_url The js_code parameter must be a string that contains JavaScript, such as alert('hello'). The code_url parameter must contain the URL of a JavaScript .js file. You must include at least one of these parameters, and you can include both. And you can send multiple compilation_level The value of this parameter indicates the degree of compression and optimization to apply to your JavaScript. There are three possible compilation levels: WHITESPACE_ONLY, SIMPLE_OPTIMIZATIONS, and ADVANCED_OPTIMIZATIONS. The compilation_level parameter defaults to SIMPLE_OPTIMIZATIONS. Restful API
  • 7. output_info The value of this parameter indicates the kind of information that you want from the compiler. There are four possible kinds of output: compiled_code, warnings, errors, and statistics. output_format The format for the Closure Compiler service's output. There are three possible output formats: text, json, or xml. The output_format parameter defaults to text. You can send a post request to the API url by sending the above specified request parameters and the response of the request will be the compiled code which you can save into a file and use in your project.
  • 8. Closure Compiler comes as a java application which you can download and use it from command line. 1. Download the latest zip file from http://closure-compiler.googlecode.com/files/compiler-latest.zip And save it in a directory. 2. Extract compiler.jar file from it and save it in the same folder. 3. Create a js file and compile it by using the following command java -jar compiler.jar --js hello.js --js_output_file hello-compiled.js This command will compile hello.js and store the compiled code in hello-compiled.js file. So, these are the different ways we can use closure compiler. Using Rest api among the three will be the better option to smoothen our development process. Java Application
  • 9. Closure compiler provides three levels of compilation. You should choose one of them while compiling your code. 1. WHITESPACE_ONLY 2. SIMPLE_OPTIMIZATIONS 3. ADVACNED_OPTIMIZATIONS Compilation Levels
  • 10. This compilation level removes comments from your code and also removes line breaks, unnecessary spaces, and other whitespace. Optimizing the following snippet of code: function helloWorld(message) { alert(message); } helloWorld("Hello, Google Closure Compiler! Thank you so much!"); with whitespace_only gives the following code function helloWorld(message){alert(message)}helloWorld("Hello, Google Closure Compiler! Thank you so much!"); The output JavaScript is functionally identical to the source JavaScript. It provides the least compression of the three levels. 1. WHITESPACE_ONLY
  • 11. This compilation level performs the same operations of WHITESPACE_ONLY, but it also does more optimization by renaming local variables in functions and modifying expressions. Optimizing the following snippet of code: function helloWorld(message) { alert(message); } helloWorld("Hello, Google Closure Compiler! Thank you so much!"); with SIMPLE_OPTIMZATIONS gives the following code function helloWorld(a){alert(a)}helloWorld("Hello, Google Closure Compiler! Thank you so much!"); As this level renames only symbols that are local to functions, it does not interfere with the interaction between the compiled JavaScript and other JavaScript. 2. SIMPLE_OPTIMIZATIONS
  • 12. Compilation with simple_optimzations always preserves the functionality of syntactically valid JavaScript, provided that the code does not access local variables using string names (by using eval() statements, for example). SIMPLE_OPTIMIZATIONS is the default compilation level.
  • 13. This compilation level performs the same transformations as SIMPLE_OPTIMZATIONS, but adds a variety of more aggressive global transformations to achieve the highest compression of all three levels. This level compresses JavaScript well beyond what is possible with other tools. Optimizing the following snippet of code: function helloWorld(message) { alert(message); } helloWorld("Hello, Google Closure Compiler! Thank you so much!"); with ADVANCED_OPTIMZATIONS gives the following code alert("Hello, Google Closure Compiler! Thank you so much!"); Here the function call is replaced with the body of the function and removed the function definition. 3. ADVANCED_OPTIMIZATIONS
  • 14. To enable this extreme compression, ADVANCED_OPTIMIZATIONS makes strong assumptions about the compiled code. If your code does not conform to those assumptions, ADVANCED_OPTIMIZATIONS will produce code that does not run. The ADVANCED_OPTIMIZATIONS transformations include: 1. more aggressive renaming: Renames global variables, function names and properties along with local variables and parameters. 2. dead code removal: Removes any unused functions or code. 3. global inlining: Replaces some function calls with the body of the function.
  • 15. Thank You Prasad Kancharla, Lead Software Developer Riktam Technology Consulting Pvt. Ltd., Tel.+91 9848558696 (India) http://www.riktamtech.com http://prasadkancharla.blogspot.in/ http://labs.riktamtech.com