“RequireJS is a JavaScript file and module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino.

Slides:



Advertisements
Similar presentations
Write Better Javascript with RequireJS. What is RequireJS?
Advertisements

© Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice. Pronq IDE – Collaboration.
JavaScript and OSGi Simon Kaegi, Orion Project Co-lead IBM
© 2014 IBM Corporation Empowering the IBM ecosystem Introduction to Developing applications using node.js on Bluemix IBM Ecosystem Development Instructors.
JavaScript: JS301 Week 1: An Introduction to JavaScript.
Jerry Neal. Agenda ➢ About Node ➢ Modules ➢ Node Architecture ➢ NPM ➢ FAQ ➢ Other Awesome Modules! get ready to node, this session is hands on!
COM311H Zheng, School of C&M, UUJ1 Dynamic Web Authoring JavaScript Basics (Array and Function)
Building a large scale JavaScript application in TypeScript Alexandru Dima Microsoft.
Nov 23, 2014 Sofia var title = “RequireJS - a brand new world!”; var info = { name: “Bogoi Bogdanov”, otherOptional: “Managing Partner at Empters Ltd.”
Unleash the Power of JavaScript Tooling Telerik Software Academy End-to-end JavaScript Applications.
GruntJS The JavaScript Task Runner. What is Grunt? A build tool for JavaScript Uses Node to run A Gruntfile is actually just a JavaScript file Therefore,
CSCI 3100 Tutorial 3 JavaScript & Node.js Presented by SU Yuxin Department of Computer Science and Engineering The Chinese University of Hong Kong 1.
North Shore.NET User Group Our Sponsors. North Shore.NET User Group Check out our new web site Next Meeting
Client Side Dev. Toolkit HTML5 JavaScript CSS (and Less, but not today) Bootstrap Knockout.js Require.js (moving to Browserify) Toastr Visual Studio and.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Chapter 6 DOJO TOOLKITS. Objectives Discuss XML DOM Discuss JSON Discuss Ajax Response in XML, HTML, JSON, and Other Data Type.
JavaScript & Metaperformance Douglas Crockford Yahoo! Inc.
Java Server Pages (JSP) Presented by: Ananth Prasad & Alex Ivanov May 10, 2001.
WORKSHOP: BUILDING A WEBAPP STEP BY STEP by Ohad Kravchick Fluent 2013 May 28th, 2013 Rate me:
REAL WORLD SPA A KNOCKOUT CASE STUDY Cory House | bitnative.com | speakerrate.com/talks/27181.
Sayed Ahmed Computer Science and Engineering, BUET, Bangladesh MSc, Computer Science, Canada
Ajax Basics The XMLHttpRequest Object. Ajax is…. Ajax is not…. Ajax is not a programming language. Ajax is not a programming language. Ajax is a methodology.
Philly.NET Hands-on Labs JAVASCRIPT SERIES. July 9: JavaScript Syntax Visual Studio ◦Projects ◦Editors ◦Debugging ◦Script blocks ◦Minification and bundling.
JQUERY | INTRODUCTION. jQuery  Open source JavaScript library  Simplifies the interactions between  HTML document, or the Document Object Model (DOM),
The Evils of Copy and Paste Presented by Daniel Daugherty
JavaScript Patterns and Node Idioms by Rob Richardson
Dynamic Languages User Group Feb 7, DynApi Javascript Library.
AMD and RequireJS Splitting JavaScript Code into Dependent Modules Software University Technical Trainers SoftUni Team.
Canopy walk through Single-Page Apps (SPAs) Benjamin Howarth Freelancer, Code Gecko Umbraco UK Festival, Fri 30 th Oct 2015 CODE GECKO.
Angular Typescript RequireJS By Chris van Beek and Frank Folsche Luminis Arnhem.
Plug-in Architectures Presented by Truc Nguyen. What’s a plug-in? “a type of program that tightly integrates with a larger application to add a special.
Getting Started with Aurelia
JavaScript scope and closures
JavaScript Unit Test by MinHo Kim (Dexter Developer Guide)
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
Thực hiện: D3 GVLT: BROWERS. Browser Compatibility I Check the compatibility II Tools III.
JQUERY AND AJAX
TypeScript : All parts are good Andriy Deren CEO, Onlizer
Testing Your Alfresco Add-ons Michael Suzuki Software Engineer.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Javascript Design Patterns. AMD & commonJS. RequireJS Marc Torrent Vernetta.
JavaScript Patterns to Clean Up Your Code Dan Wahlin.
Getting to Know Grunt By Writing Your Own
I18n - DateTime ASP.NET MVC. I18n DateTime – EF changes  In model classes, use attributes  DataType(DataType.DateTime)  DataType(DataType.Date)  DataType(DataType.Time)
Node.js Modules Header Mastering Node.js, Part 2 Eric W. Greene
Introduction to MEAN (JavaScript Full Stack Development)
Building Desktop Apps with Node.js and Electron
Angular 2 with ASP.NET Core in Practice
Angular 4 + TypeScript Getting Started
Client Side Dev.
Modules, Babel, RequireJS, Other JavaScript Module Systems
Chapter 4: HTML5 Media - <video> & <audio>
Google Web Toolkit - Gufran Mohammed
SharePoint Bruger Gruppe (SPBG) SharePoint Framework Introduction
3 Things Everyone Knows About Node JS That You Don't
In SharePoint A Practical Guide.
Node.js Packages Header Mastering Node.js, Part 4 Eric W. Greene
Nick Trogh Technical Evangelist, Microsoft.
Client-Side Web Technologies
JavaScript an introduction.
NodeJS coding basics L. Grewe.
03 | Building a Backend with Socket.IO and Mongo
Unit 6 part 3 Test Javascript Test.
Cordova & Cordova Plugin Installation and Management
INTRODUCTION TO By Stepan Vardanyan.
Console Use. Console Use Exit Console Run File.
CS 4722 Computer Graphics and Multimedia Spring 2018
Introduction.
Optimizing Your JavaScript App for Performance
Presentation transcript:

“RequireJS is a JavaScript file and module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino and Node. Using a modular script loader like RequireJS will improve the speed and quality of your code.” IE compatible ✔ Firefox compatible ✔ Safari compatible ✔ Chrome compatible ✔ Opera compatible ✔ All good!!!!

Why do we use Modules? For better decoupling and maintainability Reusability To avoid naming collisions To facilitate unit testing

Module Pattern var MODULE = (function () { var my = {}, privateVariable = 1; my.moduleProperty = 1; my.getPrivateVariable = function () { return privateVariable; }; return my; }()); MODULE.getPrivateVariable();

What are AMD modules and why should we think about using them? Asynchronous Module Definition keeps the global namespace free less cumbersome to keep track of file dependencies encourages decoupling dynamic code loading (ie. If(true) loadThisFile() )

AMD Module definition define([“dependency”], function(dependency) { var value; function init() { value = dependency.getValue(); } return { init:init }; });

Common JS Module definition define( function(require, exports, module) { var value, dependency = require(‘dependency1’); function init() { value = dependency.getValue(); } exports.init = init; });

simplified CommonJS wrapping define( function(require) { var value, dependency = require(‘dependency’); function init() { value = dependency.getValue(); } return { init:init }; }); CommonJS-wrapper-and-standard-AMD-define

Returning name/value objects define( { color: “orange”, size: “medium” });

Returning Constructor Functions define(function(require) { function Model( id ) { var self = this, name = “Model: ” + id; this.getName = function() { return name; } return Model; });

main.js – require.config({}) require.config({ paths: { // map shared business logic MainGameController : "components/com_pchblackjack_content/assets/js/…, // map template specific views MainGameView : "templates/pchblackjack_desktop/js/game/MainGameView", } }); require( ["MainGameController"], function (controller) { controller.init(); });

text!plugin Loads in html as a dependency – define(["text!howtoplaytmpl"], function(tmpl) In-lined into optimized build – define('text!howtoplaytmpl',[],function () { return ' \r\n\t }

Dependency Injection swappable implementations – Use a mock service to simulate data using the map config. Let’s try using SoundJS instead of HowlerJS!

Optimization Use Node.js or Java to build your project Useful links: – Explains the basics: – Show all options: /example.build.js Time for some Grunt work!

Using Grunt with Node.js Install node.js npm install –g grunt cli package.json – Gather your tools – npm install [module] –save-dev Gruntfile.js – Create your requirejs task

Too many options! The optimization process can be daunting. Start early! Why can’t I load dependencies dynamically after optimization? AppDir, baseUrl, dir, … durrrrrrrr Shim – Stay away if possible Wrap.startFile/endFile – keep all your code in anonymous function

Continued Reading Check out Backbone.js and how requirejs can be used effectively. – backbone-using-modules/ – fundamentals/#wrapping-models-views-and- other-components-with-amd