SlideShare une entreprise Scribd logo
1  sur  32
Grails Asset Pipeline Plugin
By: Ali Tanwir
Content
➔ Overview
➔ Advantages over Standard grails asset Resource Plugin
➔ Usage?
➔ Assets Bundling
➔ Assets Minification
➔ Behaviour With and Without Asset-Pipeline
➔ Developing with Asset-Pipeline
◆ Javascript Manifest file: application.js
◆ Css Manifest file: application.css
◆ Directives
◆ Dynamic Directives
◆ Including Assets in Grails app views
◆ Linking to Assets in GSP views
◆ How to add page specific file
➔ Other References
Overview
● The Asset-Pipeline is a plugin used for resource management i.e.,
managing and processing static assets in Grails applications.
● Asset-Pipeline functions include processing and minification of both CSS
and JavaScript files during compile time.
● It is also capable of being extended to compile custom static assets, such
as LESS, CoffeeScript, SASS.
Advantages over Standard
grails asset Resource Plugin
● Processing in development mode is faster
● Much faster startup time of application than resource plugin
● Debugging is much easier that resource plugin
● Assets in a directory or its sub-directories calls with single line of code
● Much better support for minification of assets for both JS and CSS
● Minify assets and compile before WAR is built
● Reduced hanging up application boot time during file process
● Manifest and taglibs are much simpler
● Compression, minification, and cache-digests built in process with plugin,
hence it reduced dependencies
Usage?
● Add plugin in BuildConfig.groovy
Note: Grails 2.4 automatically supports Asset pipeline plugin.
● Asset Pipeline automatically creates folders within grails app directory:
We have to put our asset resources within these directory. We can create our
sub folders as per our requirement and include these into layouts.
Assets Bundling
In development mode, stylesheets and javascripts will be included as
individual script tags. This is intended to make it easier for debugging.
Bundling is enabled in all other environments and can be forced in
development mode by adding,
to Config.groovy file.
grails.assets.bundle=true
Assets Minification
● During war build assets are also minified using UglifierJs. To disable this
feature we can add the following option to a config:
● Closure can be enabled/disabled entirely as well as configured via various
options.
grails.assets.minifyJs = false
Behaviour With and
Without Asset-Pipeline
Without Asset-Pipeline
● Layout is littered with tags
● Each tag is a request to the server
With Asset-Pipeline
● Assets are transpiled, concatenated, minified, gzipped into one file per
type
● One server hit per file type
Without Asset-Pipeline
● Browser cache isn't properly used,
With Asset-Pipeline
● Initial Request - Good Cache Headers,
● Next Request - Cache Hit
Without Asset-Pipeline
● Limited to browser-supported languages
i.e. CSS and JavaScript
With Asset-Pipeline
● Can use anything that transpiles to browser-supported languages
ex: SASS, LESS, CoffeeScript, ClojureScript …
Developing with Asset-Pipeline
● Asset-Pipeline is going to be installed by default in grails application
starting with a Grails version 2.4.
● Let’s start with creating a sample app,
grails create-app demo
● Directory structure of Asset-Pipeline,
Javascript Manifest File: application.js
CSS Manifest File: application.css
Directives
● require - It includes single file into manifest
● require_tree - It includes all files recursively and their all sub-directories in
the path
● require_self - It inserts the body of current file
● require_full_tree - It includes all files from all plugins that contains a
relative path
● encoding - It sets processor encoding i.e. UTF-8, ANSI or Latin1
In JavaScript files, the directive begins with '//='. These directives tell us which
files should be injected into this JavaScript file and in what order.
Dynamic Directives
The asset-pipeline require directives also support the use of the Groovy
Templates via the GStringTemplateEngine.
or,
//= require ${grails.util.Environment.currentEnvironment.toString() ==
'DEVELOPMENT' ? 'ember.debug.js' : 'ember.prod.js'}
//= require ${grails.util.Environment.currentEnvironment == grails.util.
Environment.DEVELOPMENT ? 'ember.debug.js' : 'ember.prod.js'}
Including asset in grails app views
Asset pipeline provides several new tag libs for including javascript and css
into your gsp files. Example,
These helpers will automatically adjust to point to the cache-digested versions
of the files when running in a non-development environment.
Linking to Assets in GSP views
● In GSP views, we can also reference images included in the asset-pipeline
with the following tag:
● Assets can also be referenced within subdirectories if required and simply
require the use of the relative path.
<asset:image src="logo.png" width="200" height="200"/>
<asset:image src="icons/delete.png"/>
● It is also possible to return an assetPath as a string for injection in your
own tags:
● It is also possible to execute a code section only if an asset exists or to
simply test for existence,
or,
<link href="${assetPath(src: 'manifest.json')}"/>
<asset:assetPathExists src="test.js">
This will only be displayed if the asset exists
</asset:assetPathExists>
asset.assetPathExists(src: 'test.js') //returns true or false
How to add Page Specific file
● specific.js file code
var pageSpecific = function () {
console.log("Hello from Specific page!")
};
$(document).ready(function () {
if ($(document.body).data('page') ==
('specific')) {
pageSpecific()
}
});
● Add this line to the layouts/main.gsp page <body> tag:
● specific/index.gsp
<body data-page="${pageProperty(name:'body.data-page')}">
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta name="layout" content="main"/>
</head>
<body data-page="specific">
<p>Hello from Specific!</p>
</body>
</html>
Other References
● http://bertramdev.github.io/grails-asset-pipeline/guide/configuration.html
● http://matthewbusche.com/blog2/2015/01/05/using-grails-assets-when-
you-cant-use-the-asset-tag/
● http://tednaleid.github.io/asset-pipeline-presentation/?full#1
Thank you!

Contenu connexe

Tendances

Distributed Locking in Kubernetes
Distributed Locking in KubernetesDistributed Locking in Kubernetes
Distributed Locking in KubernetesRafał Leszko
 
Where is my cache architectural patterns for caching microservices by example
Where is my cache  architectural patterns for caching microservices by exampleWhere is my cache  architectural patterns for caching microservices by example
Where is my cache architectural patterns for caching microservices by exampleRafał Leszko
 
GitBucket: Open source self-hosting Git server built by Scala
GitBucket: Open source self-hosting Git server built by ScalaGitBucket: Open source self-hosting Git server built by Scala
GitBucket: Open source self-hosting Git server built by Scalatakezoe
 
Build Fast WordPress Site With Gatsby
Build Fast WordPress Site With GatsbyBuild Fast WordPress Site With Gatsby
Build Fast WordPress Site With GatsbyImran Sayed
 
[Srijan Wednesday Webinar] How to Run Stateless and Stateful Services on K8S ...
[Srijan Wednesday Webinar] How to Run Stateless and Stateful Services on K8S ...[Srijan Wednesday Webinar] How to Run Stateless and Stateful Services on K8S ...
[Srijan Wednesday Webinar] How to Run Stateless and Stateful Services on K8S ...Srijan Technologies
 
Architectural patterns for high performance microservices in kubernetes
Architectural patterns for high performance microservices in kubernetesArchitectural patterns for high performance microservices in kubernetes
Architectural patterns for high performance microservices in kubernetesRafał Leszko
 
Groovy grailstutorial
Groovy grailstutorialGroovy grailstutorial
Groovy grailstutorialRasmita Patra
 
The Anatomy Of A Performance Audit
The Anatomy Of A Performance AuditThe Anatomy Of A Performance Audit
The Anatomy Of A Performance AuditSam Bhagwat
 
Intro to creating kubernetes operators
Intro to creating kubernetes operators Intro to creating kubernetes operators
Intro to creating kubernetes operators Juraj Hantak
 
The Evolution of Distributed Systems on Kubernetes
The Evolution of Distributed Systems on KubernetesThe Evolution of Distributed Systems on Kubernetes
The Evolution of Distributed Systems on KubernetesBilgin Ibryam
 
GitBucket: Git Centric Software Development Platform by Scala
GitBucket:  Git Centric Software Development Platform by ScalaGitBucket:  Git Centric Software Development Platform by Scala
GitBucket: Git Centric Software Development Platform by Scalatakezoe
 
Blazing fast sites using Blaze, Hybrid CMS NYC
Blazing fast sites using Blaze, Hybrid CMS NYCBlazing fast sites using Blaze, Hybrid CMS NYC
Blazing fast sites using Blaze, Hybrid CMS NYCJesus Manuel Olivas
 
What next after microservices
What next after microservicesWhat next after microservices
What next after microservicesBilgin Ibryam
 
Build Your Kubernetes Operator with the Right Tool!
Build Your Kubernetes Operator with the Right Tool!Build Your Kubernetes Operator with the Right Tool!
Build Your Kubernetes Operator with the Right Tool!Rafał Leszko
 
The evolving container landscape
The evolving container landscapeThe evolving container landscape
The evolving container landscapeNilesh Trivedi
 
How to keep maintainability of long life Scala applications
How to keep maintainability of long life Scala applicationsHow to keep maintainability of long life Scala applications
How to keep maintainability of long life Scala applicationstakezoe
 
Kubecon 2019_eu-k8s-secrets-csi
Kubecon 2019_eu-k8s-secrets-csiKubecon 2019_eu-k8s-secrets-csi
Kubecon 2019_eu-k8s-secrets-csiRita Zhang
 
High Availability - Brett Thurber - ManageIQ Design Summit 2016
High Availability - Brett Thurber - ManageIQ Design Summit 2016High Availability - Brett Thurber - ManageIQ Design Summit 2016
High Availability - Brett Thurber - ManageIQ Design Summit 2016ManageIQ
 
Azure kubernetes service (aks)
Azure kubernetes service (aks)Azure kubernetes service (aks)
Azure kubernetes service (aks)Akash Agrawal
 
Manuel Hurtado. Couchbase paradigma4oct
Manuel Hurtado. Couchbase paradigma4octManuel Hurtado. Couchbase paradigma4oct
Manuel Hurtado. Couchbase paradigma4octParadigma Digital
 

Tendances (20)

Distributed Locking in Kubernetes
Distributed Locking in KubernetesDistributed Locking in Kubernetes
Distributed Locking in Kubernetes
 
Where is my cache architectural patterns for caching microservices by example
Where is my cache  architectural patterns for caching microservices by exampleWhere is my cache  architectural patterns for caching microservices by example
Where is my cache architectural patterns for caching microservices by example
 
GitBucket: Open source self-hosting Git server built by Scala
GitBucket: Open source self-hosting Git server built by ScalaGitBucket: Open source self-hosting Git server built by Scala
GitBucket: Open source self-hosting Git server built by Scala
 
Build Fast WordPress Site With Gatsby
Build Fast WordPress Site With GatsbyBuild Fast WordPress Site With Gatsby
Build Fast WordPress Site With Gatsby
 
[Srijan Wednesday Webinar] How to Run Stateless and Stateful Services on K8S ...
[Srijan Wednesday Webinar] How to Run Stateless and Stateful Services on K8S ...[Srijan Wednesday Webinar] How to Run Stateless and Stateful Services on K8S ...
[Srijan Wednesday Webinar] How to Run Stateless and Stateful Services on K8S ...
 
Architectural patterns for high performance microservices in kubernetes
Architectural patterns for high performance microservices in kubernetesArchitectural patterns for high performance microservices in kubernetes
Architectural patterns for high performance microservices in kubernetes
 
Groovy grailstutorial
Groovy grailstutorialGroovy grailstutorial
Groovy grailstutorial
 
The Anatomy Of A Performance Audit
The Anatomy Of A Performance AuditThe Anatomy Of A Performance Audit
The Anatomy Of A Performance Audit
 
Intro to creating kubernetes operators
Intro to creating kubernetes operators Intro to creating kubernetes operators
Intro to creating kubernetes operators
 
The Evolution of Distributed Systems on Kubernetes
The Evolution of Distributed Systems on KubernetesThe Evolution of Distributed Systems on Kubernetes
The Evolution of Distributed Systems on Kubernetes
 
GitBucket: Git Centric Software Development Platform by Scala
GitBucket:  Git Centric Software Development Platform by ScalaGitBucket:  Git Centric Software Development Platform by Scala
GitBucket: Git Centric Software Development Platform by Scala
 
Blazing fast sites using Blaze, Hybrid CMS NYC
Blazing fast sites using Blaze, Hybrid CMS NYCBlazing fast sites using Blaze, Hybrid CMS NYC
Blazing fast sites using Blaze, Hybrid CMS NYC
 
What next after microservices
What next after microservicesWhat next after microservices
What next after microservices
 
Build Your Kubernetes Operator with the Right Tool!
Build Your Kubernetes Operator with the Right Tool!Build Your Kubernetes Operator with the Right Tool!
Build Your Kubernetes Operator with the Right Tool!
 
The evolving container landscape
The evolving container landscapeThe evolving container landscape
The evolving container landscape
 
How to keep maintainability of long life Scala applications
How to keep maintainability of long life Scala applicationsHow to keep maintainability of long life Scala applications
How to keep maintainability of long life Scala applications
 
Kubecon 2019_eu-k8s-secrets-csi
Kubecon 2019_eu-k8s-secrets-csiKubecon 2019_eu-k8s-secrets-csi
Kubecon 2019_eu-k8s-secrets-csi
 
High Availability - Brett Thurber - ManageIQ Design Summit 2016
High Availability - Brett Thurber - ManageIQ Design Summit 2016High Availability - Brett Thurber - ManageIQ Design Summit 2016
High Availability - Brett Thurber - ManageIQ Design Summit 2016
 
Azure kubernetes service (aks)
Azure kubernetes service (aks)Azure kubernetes service (aks)
Azure kubernetes service (aks)
 
Manuel Hurtado. Couchbase paradigma4oct
Manuel Hurtado. Couchbase paradigma4octManuel Hurtado. Couchbase paradigma4oct
Manuel Hurtado. Couchbase paradigma4oct
 

Similaire à Grails Asset Pipeline Plugin

Understanding asset pipeline plugin
Understanding asset pipeline pluginUnderstanding asset pipeline plugin
Understanding asset pipeline pluginRailsCarma
 
Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpackNodeXperts
 
LasCon 2014 DevOoops
LasCon 2014 DevOoops LasCon 2014 DevOoops
LasCon 2014 DevOoops Chris Gates
 
GlusterFS Containers
GlusterFS ContainersGlusterFS Containers
GlusterFS ContainersMohamed Ashiq
 
The Need for Speed - SMX Sydney 2013
The Need for Speed - SMX Sydney 2013The Need for Speed - SMX Sydney 2013
The Need for Speed - SMX Sydney 2013Bastian Grimm
 
Introduction to Grails 2013
Introduction to Grails 2013Introduction to Grails 2013
Introduction to Grails 2013Gavin Hogan
 
Magic with groovy & grails
Magic with groovy & grailsMagic with groovy & grails
Magic with groovy & grailsGeorge Platon
 
GWT Training - Session 1/3
GWT Training - Session 1/3GWT Training - Session 1/3
GWT Training - Session 1/3Faiz Bashir
 
Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalabilityTwinbit
 
Operating PostgreSQL at Scale with Kubernetes
Operating PostgreSQL at Scale with KubernetesOperating PostgreSQL at Scale with Kubernetes
Operating PostgreSQL at Scale with KubernetesJonathan Katz
 
Config BuildConfig
Config BuildConfigConfig BuildConfig
Config BuildConfigVijay Shukla
 
Ranger admin dev overview
Ranger admin dev overviewRanger admin dev overview
Ranger admin dev overviewTushar Dudhatra
 

Similaire à Grails Asset Pipeline Plugin (20)

Custom plugin
Custom pluginCustom plugin
Custom plugin
 
Grails Custom Plugin
Grails Custom PluginGrails Custom Plugin
Grails Custom Plugin
 
Grails resources
Grails resourcesGrails resources
Grails resources
 
Resources plugin
Resources pluginResources plugin
Resources plugin
 
Understanding asset pipeline plugin
Understanding asset pipeline pluginUnderstanding asset pipeline plugin
Understanding asset pipeline plugin
 
Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpack
 
Gluster containers!
Gluster containers!Gluster containers!
Gluster containers!
 
LasCon 2014 DevOoops
LasCon 2014 DevOoops LasCon 2014 DevOoops
LasCon 2014 DevOoops
 
GlusterFS Containers
GlusterFS ContainersGlusterFS Containers
GlusterFS Containers
 
The Need for Speed - SMX Sydney 2013
The Need for Speed - SMX Sydney 2013The Need for Speed - SMX Sydney 2013
The Need for Speed - SMX Sydney 2013
 
Introduction to Grails 2013
Introduction to Grails 2013Introduction to Grails 2013
Introduction to Grails 2013
 
Magic with groovy & grails
Magic with groovy & grailsMagic with groovy & grails
Magic with groovy & grails
 
Introduction To Grails
Introduction To GrailsIntroduction To Grails
Introduction To Grails
 
dkr_django_slides
dkr_django_slidesdkr_django_slides
dkr_django_slides
 
Intro to sbt-web
Intro to sbt-webIntro to sbt-web
Intro to sbt-web
 
GWT Training - Session 1/3
GWT Training - Session 1/3GWT Training - Session 1/3
GWT Training - Session 1/3
 
Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalability
 
Operating PostgreSQL at Scale with Kubernetes
Operating PostgreSQL at Scale with KubernetesOperating PostgreSQL at Scale with Kubernetes
Operating PostgreSQL at Scale with Kubernetes
 
Config BuildConfig
Config BuildConfigConfig BuildConfig
Config BuildConfig
 
Ranger admin dev overview
Ranger admin dev overviewRanger admin dev overview
Ranger admin dev overview
 

Dernier

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Dernier (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Grails Asset Pipeline Plugin

  • 1. Grails Asset Pipeline Plugin By: Ali Tanwir
  • 2. Content ➔ Overview ➔ Advantages over Standard grails asset Resource Plugin ➔ Usage? ➔ Assets Bundling ➔ Assets Minification ➔ Behaviour With and Without Asset-Pipeline ➔ Developing with Asset-Pipeline ◆ Javascript Manifest file: application.js ◆ Css Manifest file: application.css ◆ Directives ◆ Dynamic Directives ◆ Including Assets in Grails app views ◆ Linking to Assets in GSP views ◆ How to add page specific file ➔ Other References
  • 3. Overview ● The Asset-Pipeline is a plugin used for resource management i.e., managing and processing static assets in Grails applications. ● Asset-Pipeline functions include processing and minification of both CSS and JavaScript files during compile time. ● It is also capable of being extended to compile custom static assets, such as LESS, CoffeeScript, SASS.
  • 4. Advantages over Standard grails asset Resource Plugin
  • 5. ● Processing in development mode is faster ● Much faster startup time of application than resource plugin ● Debugging is much easier that resource plugin ● Assets in a directory or its sub-directories calls with single line of code ● Much better support for minification of assets for both JS and CSS ● Minify assets and compile before WAR is built ● Reduced hanging up application boot time during file process ● Manifest and taglibs are much simpler ● Compression, minification, and cache-digests built in process with plugin, hence it reduced dependencies
  • 6. Usage? ● Add plugin in BuildConfig.groovy Note: Grails 2.4 automatically supports Asset pipeline plugin.
  • 7. ● Asset Pipeline automatically creates folders within grails app directory: We have to put our asset resources within these directory. We can create our sub folders as per our requirement and include these into layouts.
  • 8. Assets Bundling In development mode, stylesheets and javascripts will be included as individual script tags. This is intended to make it easier for debugging. Bundling is enabled in all other environments and can be forced in development mode by adding, to Config.groovy file. grails.assets.bundle=true
  • 9. Assets Minification ● During war build assets are also minified using UglifierJs. To disable this feature we can add the following option to a config: ● Closure can be enabled/disabled entirely as well as configured via various options. grails.assets.minifyJs = false
  • 10. Behaviour With and Without Asset-Pipeline
  • 11. Without Asset-Pipeline ● Layout is littered with tags
  • 12. ● Each tag is a request to the server
  • 13. With Asset-Pipeline ● Assets are transpiled, concatenated, minified, gzipped into one file per type ● One server hit per file type
  • 14. Without Asset-Pipeline ● Browser cache isn't properly used,
  • 15. With Asset-Pipeline ● Initial Request - Good Cache Headers,
  • 16. ● Next Request - Cache Hit
  • 17. Without Asset-Pipeline ● Limited to browser-supported languages i.e. CSS and JavaScript
  • 18. With Asset-Pipeline ● Can use anything that transpiles to browser-supported languages ex: SASS, LESS, CoffeeScript, ClojureScript …
  • 20. ● Asset-Pipeline is going to be installed by default in grails application starting with a Grails version 2.4. ● Let’s start with creating a sample app, grails create-app demo
  • 21. ● Directory structure of Asset-Pipeline,
  • 22. Javascript Manifest File: application.js
  • 23. CSS Manifest File: application.css
  • 24. Directives ● require - It includes single file into manifest ● require_tree - It includes all files recursively and their all sub-directories in the path ● require_self - It inserts the body of current file ● require_full_tree - It includes all files from all plugins that contains a relative path ● encoding - It sets processor encoding i.e. UTF-8, ANSI or Latin1 In JavaScript files, the directive begins with '//='. These directives tell us which files should be injected into this JavaScript file and in what order.
  • 25. Dynamic Directives The asset-pipeline require directives also support the use of the Groovy Templates via the GStringTemplateEngine. or, //= require ${grails.util.Environment.currentEnvironment.toString() == 'DEVELOPMENT' ? 'ember.debug.js' : 'ember.prod.js'} //= require ${grails.util.Environment.currentEnvironment == grails.util. Environment.DEVELOPMENT ? 'ember.debug.js' : 'ember.prod.js'}
  • 26. Including asset in grails app views Asset pipeline provides several new tag libs for including javascript and css into your gsp files. Example, These helpers will automatically adjust to point to the cache-digested versions of the files when running in a non-development environment.
  • 27. Linking to Assets in GSP views ● In GSP views, we can also reference images included in the asset-pipeline with the following tag: ● Assets can also be referenced within subdirectories if required and simply require the use of the relative path. <asset:image src="logo.png" width="200" height="200"/> <asset:image src="icons/delete.png"/>
  • 28. ● It is also possible to return an assetPath as a string for injection in your own tags: ● It is also possible to execute a code section only if an asset exists or to simply test for existence, or, <link href="${assetPath(src: 'manifest.json')}"/> <asset:assetPathExists src="test.js"> This will only be displayed if the asset exists </asset:assetPathExists> asset.assetPathExists(src: 'test.js') //returns true or false
  • 29. How to add Page Specific file ● specific.js file code var pageSpecific = function () { console.log("Hello from Specific page!") }; $(document).ready(function () { if ($(document.body).data('page') == ('specific')) { pageSpecific() } });
  • 30. ● Add this line to the layouts/main.gsp page <body> tag: ● specific/index.gsp <body data-page="${pageProperty(name:'body.data-page')}"> <%@ page contentType="text/html;charset=UTF-8" %> <html> <head> <meta name="layout" content="main"/> </head> <body data-page="specific"> <p>Hello from Specific!</p> </body> </html>
  • 31. Other References ● http://bertramdev.github.io/grails-asset-pipeline/guide/configuration.html ● http://matthewbusche.com/blog2/2015/01/05/using-grails-assets-when- you-cant-use-the-asset-tag/ ● http://tednaleid.github.io/asset-pipeline-presentation/?full#1