resources plugin
DESCRIPTION
Resource Plugin is a Grails plugin for managing static resources.TRANSCRIPT
![Page 1: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/1.jpg)
Grails Resources Plugin
Alidad Soleimani (Grails developer)Net Jets Inc.
alidadasb https://github.com/alidadasb
![Page 2: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/2.jpg)
Static Resource
• CSS• JS• Images
/web-app/
<link rel="..." href=...>
<g:external dir="css" file="main.css" />
![Page 3: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/3.jpg)
Static Resource
![Page 4: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/4.jpg)
Challenges• Complex Applications• Plugins resources• Dependency between resources• Multiple copies of a resource• Different version of a resource• Order of resources
![Page 5: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/5.jpg)
Managing Dependencies
• Mark Palmer’s blog
![Page 6: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/6.jpg)
Optimization & Performance• Cache resources• Minifying resources• Zipping• Bundling Resources
![Page 7: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/7.jpg)
Performance Golden Rule
• “80-90% of the end-user response time is spent on the frontend. Start there”, Steve Souders
• How can we improve web performance going forward?
![Page 8: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/8.jpg)
14 Rules for Faster-Loading Web Sites
• Rule 1 - Make Fewer HTTP Requests • Rule 2 - Use a Content Delivery Network • Rule 3 - Add an Expires Header • Rule 4 - Gzip Components • Rule 5 - Put Stylesheets at the Top • Rule 6 - Put Scripts at the Bottom • Rule 7 - Avoid CSS Expressions • Rule 8 - Make JavaScript and CSS External • Rule 9 - Reduce DNS Lookups • Rule 10 - Minify JavaScript • Rule 11 - Avoid Redirects • Rule 12 - Remove Duplicate Scripts • Rule 13 - Configure ETags • Rule 14 - Make AJAX Cacheable • “will cut 25% to 50% off response time when users request a page”
Steve Souders
![Page 9: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/9.jpg)
Grails’ static resource management
•2008 - UI Performance Plugin•2009 - Resources Plugin •Asset-pipeline
![Page 10: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/10.jpg)
Introduction to resources plugin
http://grails.org/plugin/resources Authors: Mark Palmer, Luke Daley 2009 initial version 2011 Plugin in 1.3.x 2012 shipped with Grails 2.0 Current stable version 1.2.RC2 Organization : Grails Community
![Page 11: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/11.jpg)
Resources Plugin
A plugin that provides a powerful streamlined asset pipeline
“This plugin represents a new way of declaring and linking to static resources in your application and plugins. Resource dependencies can be declared and pages simply indicate which resource modules they require. The plugin does the rest, and provides a processing pipeline for advanced optimizations.”(Colin Harrington)
![Page 12: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/12.jpg)
Defining Modules• Define inside config.groovy
• Define inside *Resources.groovy
![Page 13: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/13.jpg)
Declaring modulesMyResources.groovy
![Page 14: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/14.jpg)
Referring to Resources
Page1.gsp
![Page 15: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/15.jpg)
Defining Modules• Resources from a given module are loaded in the order they
are defined in the module
• Resources from modules are loaded in module dependency order
![Page 16: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/16.jpg)
Tag Libs• r:external : This tag renders the right kind of links to external
resources, based on their type• r:img • r:layoutResources • r:require • r:resource: This tag returns the URL to use link to a resource.
g:resource will delegate to r:resource automatically
![Page 17: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/17.jpg)
Defining Layout
Main.gsp
The r:require tag tells the framework which resource modules the current GSP requires.
The <r:layoutResources/> is a placeholder for where to include the resources
![Page 18: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/18.jpg)
Referring to Resources
Page1.gsp
![Page 19: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/19.jpg)
Ad-hoc resources• As of Grails 2.0 <img> is aware of resources
![Page 20: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/20.jpg)
5 primary functions • Bundling of resources into modules with dependency
management.
• Processing of resources prior to serving them.
• Tag library to render links to resources in modules.
• Tag library to render links to other resources which are not in modules.
• Service of resources to clients based on appropriate requests.
![Page 21: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/21.jpg)
Processing of resources• Extensible pipeline of mappers
Peter Ledbrook
![Page 22: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/22.jpg)
Phases:
![Page 23: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/23.jpg)
Images:
![Page 24: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/24.jpg)
Debugging
println grailsResourceProcessor.dumpResources()
![Page 25: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/25.jpg)
Other Plugins• Cached Resources• Zipped Resources• Less CSS Resources • Modernizr for Grails
![Page 26: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/26.jpg)
Configuration
![Page 27: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/27.jpg)
YSLOW
![Page 28: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/28.jpg)
YSLOW
![Page 29: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/29.jpg)
Asset-PipeLines• On the fly processing - No more waiting for your assets to
reload after making a change• Compiled assets by generator - No more hanging up
application boot times while processing files. `grails asset-precompile`
• Reduced Dependence - The plugin has compression, minification, and cache-digests built in.
• Easy Debugging - Makes for easy debugging by keeping files seperate in development mode.
• Simpler manifests and taglibs - Read on for more information.
![Page 30: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/30.jpg)
Bundling of Resources into Modules with Dependency Management• define resource modules that have a name and contain one or
more resources• declared in separate files named like ModuleResources.groovy • separate modules block within Config.groovy• The resources can either be local to the application, and
declared with the usual map of attributes, such as dir: and file:, or external to the application, with an absolute url containing ://
![Page 31: Resources plugin](https://reader033.vdocuments.net/reader033/viewer/2022061118/5469e903af7959ff128b5ed6/html5/thumbnails/31.jpg)
Bundling of Resources into Modules with Dependency Management• require tag for the module