resources plugin

31
Grails Resources Plugin Alidad Soleimani (Grails developer) Net Jets Inc. alidadasb https://github.com/alidadasb

Upload: alidad-soleimani

Post on 17-Nov-2014

437 views

Category:

Technology


0 download

DESCRIPTION

Resource Plugin is a Grails plugin for managing static resources.

TRANSCRIPT

Page 1: Resources plugin

Grails Resources Plugin

Alidad Soleimani (Grails developer)Net Jets Inc.

alidadasb https://github.com/alidadasb

Page 2: Resources plugin

Static Resource

• CSS• JS• Images

/web-app/

<link rel="..." href=...>

<g:external dir="css" file="main.css" />

Page 3: Resources plugin

Static Resource

Page 4: Resources plugin

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

Managing Dependencies

• Mark Palmer’s blog

Page 6: Resources plugin

Optimization & Performance• Cache resources• Minifying resources• Zipping• Bundling Resources

Page 7: Resources plugin

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

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

Grails’ static resource management

•2008 - UI Performance Plugin•2009 - Resources Plugin •Asset-pipeline

Page 10: Resources plugin

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

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

Defining Modules• Define inside config.groovy

• Define inside *Resources.groovy

Page 13: Resources plugin

Declaring modulesMyResources.groovy

Page 14: Resources plugin

Referring to Resources

Page1.gsp

Page 15: Resources plugin

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

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

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

Referring to Resources

Page1.gsp

Page 19: Resources plugin

Ad-hoc resources• As of Grails 2.0 <img> is aware of resources

Page 20: Resources plugin

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

Processing of resources• Extensible pipeline of mappers

Peter Ledbrook

Page 22: Resources plugin

Phases:

Page 23: Resources plugin

Images:

Page 24: Resources plugin

Debugging

println grailsResourceProcessor.dumpResources()

Page 26: Resources plugin

Configuration

Page 27: Resources plugin

YSLOW

Page 28: Resources plugin

YSLOW

Page 29: Resources plugin

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

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

Bundling of Resources into Modules with Dependency Management• require tag for the module