SlideShare a Scribd company logo
Loadrunner
 Dependency Management,
      Script Loader
An Introduction
Events
Every JavaScript developer is familiar with
Events.
"When X happens, do Y"

X.bind('happens', function() {
    Y();
});
Dependencies
A Dependency says:
"Wait for X before doing Y"
Yes, ok,
that sounds the same.
Wait for X before doing Y

Two key differences:
   1. Y only gets fired once.
   2. If X has already happened, Y fires
      immediately.
You are already familiar with this behaviour
for “document ready”.
Script Loading
Script loading is a type of Dependency
Problem.
For example,
"Wait for jQuery before doing Ajax"
This could be rephrased as:
"using jQuery, do Ajax"
using

Loadrunner specifies dependencies with the
using function:


using('/lib/jquery.js',
   function() {
     $.ajax({ … });
   }
);
using(multiple)

We can depend on multiple scripts this way:


using(
   '/lib/jquery.js',
   ‘plugin.js’,
   function() {
     $.ajax({ … });
   }
);
using(sequence)
We can also require that scripts are loading
in sequence, by passing an array.
eg., Load jQuery, then jQuery UI.
using([
   '/lib/jquery.js',
   ‘/lib/jquery.ui.js‘
   ],
   function() {
      $.ajax({ … });
   }
);
Asynchronous
Since Loadrunner has to wait for the
dependencies to be fulfilled, the "using"
function makes your code asynchronous.
console.log(1);
using('/lib/jquery.1.7.js',
   function() {
     console.log(2);
   }
);
console.log(3);
// => 1, 3, 2
[Asynchronous]
Unless the scripts have already been loaded.

using('/lib/jquery.1.7.js',
   function() {
     console.log(1);
     using('/lib/jquery.1.7.js',
     function() {
       console.log(2);
     }
     console.log(3);
   }
);
// => 1, 2, 3
Awesome?

This script dependency loader is awesome,
but we can see two problems with it.
1. Scripts must load into the global scope.
2. It waits for the script to load, but does
   not wait for the functions to be ready.
For example, if ‘api.js’ is:

using('/lib/jquery.1.7.js',
  function() {
     window.api = {};
     api.wizardry = function() {
        alert('Wahoo');
     };
  })
});

The ‘api’ won’t be ready when we want it:

using('/js/api.js', function() {
  api.wizardry();
});
“ReferenceError: api is not defined”
API ready
Besides script loading, there are lots of
reasons why the API might take time to be
ready:
•   Creating DOM nodes, like iframes.
•   Ajax communications
•   setTimeouts
•   Animation
Modules

We can solve these problems by wrapping
our scripts as Loadrunner "modules".


To create a module, we wrap our script in a
provide function.
For example:
provide(function(exports) {
  using('/lib/jquery.1.7.js',
    function() {
      var api = {};
      api.wizardry = function() {
         alert('Wahoo');
      };
      exports(api);
    });
  });
});
The provide function uses exports to declare
when it is ready, and return the object it
created.
We can now depend on the result of this
module in our using statement:
using.path = '/js';
using('api', function(api) {
  api.wizardry();
});

We state the dependency in a different way:
we leave off the ".js" extension to tell
Loadrunner that we want a module.
The callback function receives a parameter
api that contains the result of the module's
exports object.
Win
Modules make life really easy.

using(‘sizzle’,'api',‘animation’,
   function($, api, anim) {
     anim($(‘#thing’), api.text);
   }
);
Collecting params
If you like, you can collect parameters

using(‘sizzle’,'api',‘animation’)
  .as(
     function(all) {
       all.animation(all.api.text);
     }
  );
Collecting params
Or mix techniques

using(‘sizzle’,'api',‘animation’)
  .as(
     function(all, $, api, anim) {
       all.animation(api.text);
     }
  );
Module-ify
Scripts like jQuery aren’t provided as
modules, but we can make a module that
takes advantage of their noConflict mode.

provide(function(exports) {
  using(‘/lib/jquery.js’,
     function() {
       exports(jQuery.noConflict());
     }
  );
});
Folders
Modules can make our JS folder readable.

>ls
loadrunner.js
lib/jquery.js
imports/jquery.js
api/api.js
api/iframe_loader.js
anim/animation.js
HTML
Loadrunner can be loaded with data
attributes.
<script src=”loadrunner.js”
 data-path=”/js”
 data-main=”main.js” />

Path is the folder of your Loadrunner
modules (defaults to path containing
loadrunner.js).
Main is the first script to execute.
Summary
• Use Loadrunner modules as much as you
  can.

• Only export your module when it’s ready.
• Watch out for asynchronous functions.
Go forth and load.

More Related Content

What's hot

Workshop 22: React-Redux Middleware
Workshop 22: React-Redux MiddlewareWorkshop 22: React-Redux Middleware
Workshop 22: React-Redux Middleware
Visual Engineering
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte I
Visual Engineering
 
Workshop 3: JavaScript build tools
Workshop 3: JavaScript build toolsWorkshop 3: JavaScript build tools
Workshop 3: JavaScript build tools
Visual Engineering
 
Workshop 19: ReactJS Introduction
Workshop 19: ReactJS IntroductionWorkshop 19: ReactJS Introduction
Workshop 19: ReactJS Introduction
Visual Engineering
 
Workshop Intro: FrontEnd General Overview
Workshop Intro: FrontEnd General OverviewWorkshop Intro: FrontEnd General Overview
Workshop Intro: FrontEnd General Overview
Visual Engineering
 
Workshop 15: Ionic framework
Workshop 15: Ionic frameworkWorkshop 15: Ionic framework
Workshop 15: Ionic framework
Visual Engineering
 
Dependency Injection @ AngularJS
Dependency Injection @ AngularJSDependency Injection @ AngularJS
Dependency Injection @ AngularJS
Ran Mizrahi
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
Ravi Mone
 
How AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design PatternsHow AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design Patterns
Ran Mizrahi
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
Mike Subelsky
 
Migrating an application from Angular 1 to Angular 2
Migrating an application from Angular 1 to Angular 2 Migrating an application from Angular 1 to Angular 2
Migrating an application from Angular 1 to Angular 2
Ross Dederer
 
Angularjs Basics
Angularjs BasicsAngularjs Basics
Angularjs Basics
Anuradha Bandara
 
Introduction to AJAX In WordPress
Introduction to AJAX In WordPressIntroduction to AJAX In WordPress
Introduction to AJAX In WordPress
Caldera Labs
 
AngularJS for Java Developers
AngularJS for Java DevelopersAngularJS for Java Developers
AngularJS for Java Developers
Loc Nguyen
 
AngularJS Introduction
AngularJS IntroductionAngularJS Introduction
AngularJS Introduction
Carlos Morales
 
Building scalable applications with angular js
Building scalable applications with angular jsBuilding scalable applications with angular js
Building scalable applications with angular js
Andrew Alpert
 
AngularJS Beginners Workshop
AngularJS Beginners WorkshopAngularJS Beginners Workshop
AngularJS Beginners Workshop
Sathish VJ
 
Angular Lazy Loading and Resolve (Route Resolver)
Angular Lazy Loading and Resolve (Route Resolver)Angular Lazy Loading and Resolve (Route Resolver)
Angular Lazy Loading and Resolve (Route Resolver)
Squash Apps Pvt Ltd
 

What's hot (20)

Workshop 22: React-Redux Middleware
Workshop 22: React-Redux MiddlewareWorkshop 22: React-Redux Middleware
Workshop 22: React-Redux Middleware
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte I
 
Workshop 3: JavaScript build tools
Workshop 3: JavaScript build toolsWorkshop 3: JavaScript build tools
Workshop 3: JavaScript build tools
 
Workshop 19: ReactJS Introduction
Workshop 19: ReactJS IntroductionWorkshop 19: ReactJS Introduction
Workshop 19: ReactJS Introduction
 
Workshop Intro: FrontEnd General Overview
Workshop Intro: FrontEnd General OverviewWorkshop Intro: FrontEnd General Overview
Workshop Intro: FrontEnd General Overview
 
Workshop 15: Ionic framework
Workshop 15: Ionic frameworkWorkshop 15: Ionic framework
Workshop 15: Ionic framework
 
Dependency Injection @ AngularJS
Dependency Injection @ AngularJSDependency Injection @ AngularJS
Dependency Injection @ AngularJS
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
 
How AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design PatternsHow AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design Patterns
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
Migrating an application from Angular 1 to Angular 2
Migrating an application from Angular 1 to Angular 2 Migrating an application from Angular 1 to Angular 2
Migrating an application from Angular 1 to Angular 2
 
Angularjs Basics
Angularjs BasicsAngularjs Basics
Angularjs Basics
 
Introduction to AJAX In WordPress
Introduction to AJAX In WordPressIntroduction to AJAX In WordPress
Introduction to AJAX In WordPress
 
AngularJS for Java Developers
AngularJS for Java DevelopersAngularJS for Java Developers
AngularJS for Java Developers
 
AngularJS Introduction
AngularJS IntroductionAngularJS Introduction
AngularJS Introduction
 
Building scalable applications with angular js
Building scalable applications with angular jsBuilding scalable applications with angular js
Building scalable applications with angular js
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
AngularJS Beginners Workshop
AngularJS Beginners WorkshopAngularJS Beginners Workshop
AngularJS Beginners Workshop
 
Angular Lazy Loading and Resolve (Route Resolver)
Angular Lazy Loading and Resolve (Route Resolver)Angular Lazy Loading and Resolve (Route Resolver)
Angular Lazy Loading and Resolve (Route Resolver)
 
AngularJS - TechTalk 3/2/2014
AngularJS - TechTalk 3/2/2014AngularJS - TechTalk 3/2/2014
AngularJS - TechTalk 3/2/2014
 

Similar to Loadrunner

React Basic and Advance || React Basic
React Basic and Advance   || React BasicReact Basic and Advance   || React Basic
React Basic and Advance || React Basic
rafaqathussainc077
 
[2015/2016] JavaScript
[2015/2016] JavaScript[2015/2016] JavaScript
[2015/2016] JavaScript
Ivano Malavolta
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Nagaraju Sangam
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js frameworkBen Lin
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for JoomlaLuke Summerfield
 
JavaScript
JavaScriptJavaScript
JavaScript
Ivano Malavolta
 
Asynchronous development in JavaScript
Asynchronous development  in JavaScriptAsynchronous development  in JavaScript
Asynchronous development in JavaScript
Amitai Barnea
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)
Spike Brehm
 
NodeJS
NodeJSNodeJS
NodeJS
Alok Guha
 
JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript Misunderstood
Bhavya Siddappa
 
AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - Services
Nir Kaufman
 
JavaScript for real men
JavaScript for real menJavaScript for real men
JavaScript for real men
Ivano Malavolta
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Nicolás Bouhid
 
Explaination of angular
Explaination of angularExplaination of angular
Explaination of angular
Kan-Han (John) Lu
 
Xopus Application Framework
Xopus Application FrameworkXopus Application Framework
Xopus Application Framework
Jady Yang
 
jQuery
jQueryjQuery
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
Ricardo Silva
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJS
RajthilakMCA
 

Similar to Loadrunner (20)

React Basic and Advance || React Basic
React Basic and Advance   || React BasicReact Basic and Advance   || React Basic
React Basic and Advance || React Basic
 
[2015/2016] JavaScript
[2015/2016] JavaScript[2015/2016] JavaScript
[2015/2016] JavaScript
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Asynchronous development in JavaScript
Asynchronous development  in JavaScriptAsynchronous development  in JavaScript
Asynchronous development in JavaScript
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)
 
NodeJS
NodeJSNodeJS
NodeJS
 
JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript Misunderstood
 
AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - Services
 
JavaScript for real men
JavaScript for real menJavaScript for real men
JavaScript for real men
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
 
Explaination of angular
Explaination of angularExplaination of angular
Explaination of angular
 
Xopus Application Framework
Xopus Application FrameworkXopus Application Framework
Xopus Application Framework
 
jQuery
jQueryjQuery
jQuery
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJS
 

Loadrunner

  • 3. Events Every JavaScript developer is familiar with Events. "When X happens, do Y" X.bind('happens', function() { Y(); });
  • 6. Wait for X before doing Y Two key differences: 1. Y only gets fired once. 2. If X has already happened, Y fires immediately. You are already familiar with this behaviour for “document ready”.
  • 7. Script Loading Script loading is a type of Dependency Problem. For example, "Wait for jQuery before doing Ajax" This could be rephrased as: "using jQuery, do Ajax"
  • 8. using Loadrunner specifies dependencies with the using function: using('/lib/jquery.js', function() { $.ajax({ … }); } );
  • 9. using(multiple) We can depend on multiple scripts this way: using( '/lib/jquery.js', ‘plugin.js’, function() { $.ajax({ … }); } );
  • 10. using(sequence) We can also require that scripts are loading in sequence, by passing an array. eg., Load jQuery, then jQuery UI. using([ '/lib/jquery.js', ‘/lib/jquery.ui.js‘ ], function() { $.ajax({ … }); } );
  • 11. Asynchronous Since Loadrunner has to wait for the dependencies to be fulfilled, the "using" function makes your code asynchronous. console.log(1); using('/lib/jquery.1.7.js', function() { console.log(2); } ); console.log(3); // => 1, 3, 2
  • 12. [Asynchronous] Unless the scripts have already been loaded. using('/lib/jquery.1.7.js', function() { console.log(1); using('/lib/jquery.1.7.js', function() { console.log(2); } console.log(3); } ); // => 1, 2, 3
  • 13. Awesome? This script dependency loader is awesome, but we can see two problems with it. 1. Scripts must load into the global scope. 2. It waits for the script to load, but does not wait for the functions to be ready.
  • 14. For example, if ‘api.js’ is: using('/lib/jquery.1.7.js', function() { window.api = {}; api.wizardry = function() { alert('Wahoo'); }; }) }); The ‘api’ won’t be ready when we want it: using('/js/api.js', function() { api.wizardry(); }); “ReferenceError: api is not defined”
  • 15. API ready Besides script loading, there are lots of reasons why the API might take time to be ready: • Creating DOM nodes, like iframes. • Ajax communications • setTimeouts • Animation
  • 16. Modules We can solve these problems by wrapping our scripts as Loadrunner "modules". To create a module, we wrap our script in a provide function.
  • 17. For example: provide(function(exports) { using('/lib/jquery.1.7.js', function() { var api = {}; api.wizardry = function() { alert('Wahoo'); }; exports(api); }); }); }); The provide function uses exports to declare when it is ready, and return the object it created.
  • 18. We can now depend on the result of this module in our using statement: using.path = '/js'; using('api', function(api) { api.wizardry(); }); We state the dependency in a different way: we leave off the ".js" extension to tell Loadrunner that we want a module. The callback function receives a parameter api that contains the result of the module's exports object.
  • 19. Win Modules make life really easy. using(‘sizzle’,'api',‘animation’, function($, api, anim) { anim($(‘#thing’), api.text); } );
  • 20. Collecting params If you like, you can collect parameters using(‘sizzle’,'api',‘animation’) .as( function(all) { all.animation(all.api.text); } );
  • 21. Collecting params Or mix techniques using(‘sizzle’,'api',‘animation’) .as( function(all, $, api, anim) { all.animation(api.text); } );
  • 22. Module-ify Scripts like jQuery aren’t provided as modules, but we can make a module that takes advantage of their noConflict mode. provide(function(exports) { using(‘/lib/jquery.js’, function() { exports(jQuery.noConflict()); } ); });
  • 23. Folders Modules can make our JS folder readable. >ls loadrunner.js lib/jquery.js imports/jquery.js api/api.js api/iframe_loader.js anim/animation.js
  • 24. HTML Loadrunner can be loaded with data attributes. <script src=”loadrunner.js” data-path=”/js” data-main=”main.js” /> Path is the folder of your Loadrunner modules (defaults to path containing loadrunner.js). Main is the first script to execute.
  • 26. • Use Loadrunner modules as much as you can. • Only export your module when it’s ready. • Watch out for asynchronous functions.
  • 27. Go forth and load.