+ All Categories
Home > Technology > Make JavaScript Lean, Mean, and Clean

Make JavaScript Lean, Mean, and Clean

Date post: 16-Jul-2015
Category:
Upload: blue-raster
View: 54 times
Download: 1 times
Share this document with a friend
Popular Tags:
25
Robert Winterbottom @RWinter85 Aamir Suleman @iSpatial Slides: http://bit.ly/1Fb5ZHk Make JavaScript Lean, Mean, and Clean Mesquite C March 11 th , 2:30pm
Transcript
Page 1: Make JavaScript Lean, Mean, and Clean

Robert Winterbottom @RWinter85

Aamir Suleman @iSpatial

Slides: http://bit.ly/1Fb5ZHk

Make JavaScript Lean, Mean, and Clean

Mesquite C

March 11th , 2:30pm

Page 2: Make JavaScript Lean, Mean, and Clean

Overview

• Gulp

• RequireJS Optimizer

• Other considerations

Page 3: Make JavaScript Lean, Mean, and Clean

Gulp

• Task Automation

• Simple and Efficient

Page 4: Make JavaScript Lean, Mean, and Clean

Gulp – Common Uses

1. JSLint

2. Code Minification

3. Image Optimization

4. FTP

5. Watch files

Page 5: Make JavaScript Lean, Mean, and Clean

Gulp – What is needed?

• Install NodeJS

• Install Gulp

• Get the Ingredients

gulp-* plugins

• Make the Recipe

gulpfile.js

Page 6: Make JavaScript Lean, Mean, and Clean

Gulp - Plugin

Page 7: Make JavaScript Lean, Mean, and Clean

Gulp – More Plugins

• gulp-concat

• gulp-autoprefixer

• gulp-minify-html

• gulp-imagemin

• gulp-uglify

• http://gulpjs.com/plugins/

Page 8: Make JavaScript Lean, Mean, and Clean

Gulp - Chaining

Page 9: Make JavaScript Lean, Mean, and Clean

development workflow

• Jade HTML

• Stylus CSS on edit

• JavaScript JSLint on edit

Page 10: Make JavaScript Lean, Mean, and Clean

• Minify

• Port only require files (no jade, stylus, etc)

• FTP the build

build workflow

Page 11: Make JavaScript Lean, Mean, and Clean

Demo : GulpJS

Page 12: Make JavaScript Lean, Mean, and Clean

Build Option 2

• Concatenate JS files to a single file using

RequireJS Optimizer

Page 13: Make JavaScript Lean, Mean, and Clean

RequireJS Optimizer

• Simple to use !!!

• Open source

• Optimize your AMD

modules

• Works easily with your

favorite task runner or

directly in node.js

Page 14: Make JavaScript Lean, Mean, and Clean

What can the optimizer do for you?

• Make your app load faster

• require your css and have it

inlined into the bundle.

• Generate multiple bundles, or

layers, for single or multi page

applications, including shared

bundles.

• Minimize the number of http

requests made when your app

loads.

Page 15: Make JavaScript Lean, Mean, and Clean

src version

built

version

Page 16: Make JavaScript Lean, Mean, and Clean

src folder build folder

~ 20 items

~ 100 KB

~ 3 items

~ 44 KB

Page 17: Make JavaScript Lean, Mean, and Clean

Getting Started

• Grunt

• npm install grunt-contrib-requirejs --save

• Gulp

• npm install gulp-requirejs --save

• Node.js

• npm install requirejs --save

Installation

Dependencies• node.js

• or Java (although I have not used this approach)

• or Browser (new way to generate bundles)

Page 18: Make JavaScript Lean, Mean, and Clean

Simple example with Grunt

Page 19: Make JavaScript Lean, Mean, and Clean

Simple example with Gulp

Page 20: Make JavaScript Lean, Mean, and Clean

Build Profile

Page 21: Make JavaScript Lean, Mean, and Clean

Build Profile Explained

• baseUrl - base directory for the project

• paths - these are the packages you configured in

dojoConfig or require config

• empty: - special reserved word for empty or CDN

modules, such as esri, dijit, dojo, etc.

• name - name of your entry file (minus the .js extension), this

is where the optimizer will start looking for dependencies

• out - Where to put the bundled file

Page 22: Make JavaScript Lean, Mean, and Clean

Gotchas• plugins

• dojo/text!myTemplate.html

• CDN or empty resources

• must be specified as empty: in the build

profile

• Aliases

• full path specified in build profile, not

relative to packages.

• Example:

'MainModel': 'app/js/models/Main'

as opposed to:

'MainModel': 'models/Main'source: http://i.verylol.com/

Page 23: Make JavaScript Lean, Mean, and Clean

Additional Considerations

• Gzip

• CloudFront, CloudFlare

• AppCache – several gotchas!

• Service Workers – coming soon…

Page 24: Make JavaScript Lean, Mean, and Clean

Resources

• https://developers.arcgis.com/javascript/

• https://github.com/requirejs/example-multipage/

• http://requirejs.org

• https://github.com/requirejs/

• http://gruntjs.com/

• http://gulpjs.com/

Page 25: Make JavaScript Lean, Mean, and Clean

Questions

Github Code example

http://bit.ly/1A6JXzR

http://bit.ly/1Fb5ZHk

• @RWinter85

• @iSpatial


Recommended