Lazy Loading Techniques

Similar documents
AngularJS. Beginner's guide - part 2

3 Days Training Program

AngularJS AN INTRODUCTION. Introduction to the AngularJS framework

Single Page Applications using AngularJS

Introduction to AngularJS

Tim Roes. Android- & inovex in Karlsruhe. GDG Karlsruhe Co-Organizer.

Nagaraju Bende

Frontend Frameworks. SWE 432, Fall 2016 Design and Implementation of Software for the Web

What is AngularJS. à Javascript Framework à MVC à for Rich Web Application Development à by Google

AngularJS Fundamentals

UI Course HTML: (Html, CSS, JavaScript, JQuery, Bootstrap, AngularJS) Introduction. The World Wide Web (WWW) and history of HTML

The magic behind. Angular 2+

JavaScript: the language of browser interactions. Claudia Hauff TI1506: Web and Database Technology

Angular 4 Syllabus. Module 1: Introduction. Module 2: AngularJS to Angular 4. Module 3: Introduction to Typescript

Dynamic Web Development

AngularJS Intro Homework

Source. Developer Guide / module

Angular 2: What s new? Jonas Bandi, IvoryCode GmbH

Practical Course: Web Development Angular JS Part I Winter Semester 2016/17. Juliane Franze

Connecting Angular and CFML

AngularJS. CRUD Application example with AngularJS and Rails 4. Slides By: Jonathan McCarthy

Single Page Applications

MEAN Stack. 1. Introduction. 2. Foundation a. The Node.js framework b. Installing Node.js c. Using Node.js to execute scripts

AngularJS. CRUD Application example with AngularJS and Rails 4. Slides By: Jonathan McCarthy

Chapter 1 - Development Setup of Angular

ANGULARJS INTERVIEW QUESTIONS

JavaScript Framework: AngularJS

Sample Copy. Not For Distribution.

AngularJS. Beginner's guide - part 1

Design and Implementation of Single Page Application Based on AngularJS

AngularJS Introduction

Using AngularJS In APEX. Dan McGhan Senior Technical Consultant

THE PRAGMATIC INTRO TO REACT. Clayton Anderson thebhwgroup.com WEB AND MOBILE APP DEVELOPMENT AUSTIN, TX

We will show you how we bypassed every XSS mitigation we tested. Mitigation bypass-ability via script gadget chains in 16 popular libraries

Adding a New Application to the OSC UI

Q2D8T#YH# BYUQTUQ+ *")#+,-./,01#2../,345,67#869,3#47:#+5;<35<;=!"""""""""""# $& B675;6//=;#CD/645E!

The UIComponent Ally or Enemy?

INF5750. Introduction to JavaScript and Node.js

P a g e 1. Danish Technological Institute. Scripting and Web Languages Online Course k Scripting and Web Languages

ANGULARJS - MOCK TEST ANGULARJS MOCK TEST II

Index. Elad Elrom 2016 E. Elrom, Pro MEAN Stack Development, DOI /

Pentaho BioMe App Demo. Installation, Access & Usage Instructions

AngularJS Step By Step Tutorials. $interval([function], [delaytime], [count], [invokeapply], [parameter]);

Part 1: Data-Binding Frameworks (e.g. AngularJS)

Basics of Web Technologies

"Charting the Course... Comprehensive Angular. Course Summary

CSP ODDITIES. Michele Spagnuolo Lukas Weichselbaum

Swift by Practical Example. Justin Miller

EXPRESSIONS IN ANGULARJS

The Now Platform Reference Guide

Prototyping a Social Network. AngularJS: Firebase integration with AngularFire

The New GOLD Standard: Prototype Screen Samples Sample of the CU*BASE Menus

Simple AngularJS thanks to Best Practices

Understanding Angular Directives By Jeffry Houser

AngularJS Cookbook. 70 Recipes for AngularJS 1.2. Sascha Brink. This book is for sale at

RequireJS Javascript Modules for the Browser. By Ben Keith Quoin, Inc.

HTML DOM IN ANGULARJS

Network Automation: Ansible 101

What is Node.js? Tim Davis Director, The Turtle Partnership Ltd

Creating Effective Websites using AngularJS

JAVASCRIPT FOR BEGINNERS: The Ultimate Beginners Crash Course To Learn Javascript Quickly And Easily By Adam Vardy

and why you should care but probably don t

Angular 2 and TypeScript Web Application Development

Frontend Web Development with Angular. CC BY-NC-ND Carrot & Company GmbH

WINTER. Web Development. Template. PHP Variables and Constants. Lecture

Incremental Linking with Gold

SOGETI ANGULARJS TRAINING

Transform your skills. Change your future.

Amsterdam Las Vegas Melbourne

Getting Started with

JSON POST WITH PHP IN ANGULARJS

AngularJS - Walkthrough

Model-View-Whatever A COMPARISON OF JAVASCRIPT MVC/MVP/MVVM FRAMEWORKS. J. Tower

Light IT Up! Better Monitoring in Splunk with Custom Actions, Search Commands and Dashboards JUSTIN BROWN

Moodle JavaScript. Using AMD with RequireJS. Daniel Thee Roperto.

Demystifying Angular 2. SPAs for the Web of Tomorrow

Advance Mobile& Web Application development using Angular and Native Script

Integrating Angular with ASP.NET Core RESTful Services. Dan Wahlin

ngphotos (Grails + AngularJS)

Normal Order (Lazy) Evaluation SICP. Applicative Order vs. Normal (Lazy) Order. Applicative vs. Normal? How can we implement lazy evaluation?

Chapter 2. Operating-System Structures

Lab 6: Testing. Software Studio DataLab, CS, NTHU

Web Application Development

Nagios XI Using The Core Config Manager For Host Management

PyBossa.JS JavaScript library for PyBossa

Advance AngularJS (with.net)

Full Stack Web Developer

D3 + Angular JS = Visual Awesomesauce

Code-Reuse Attacks for the Web: Breaking XSS mitigations via Script Gadgets

Jquery Manually Set Checkbox Checked Or Not

TechWatch Report Javascript Libraries and Frameworks

- MEAN Stack חזרה. MongoDB - as the database Express - as the web framework AngularJS - as the frontend framework NodeJS- as the server platform

BOOSTING THE SECURITY OF YOUR ANGULAR 2 APPLICATION

Build Native-like Experiences in HTML5

ANGULAR 10. Christian Ulbrich (Zalari)

FRONT END WEB. {< Course Details >}

Software Exorcism: A Handbook for Debugging and Optimizing Legacy Code

Deep Dive on How ArcGIS API for JavaScript Widgets Were Built

a Very Short Introduction to AngularJS

Serverless Single Page Web Apps, Part Four. CSCI 5828: Foundations of Software Engineering Lecture 24 11/10/2016

Transcription:

Lazy Loading Techniques

Introduction Nir Kaufman AngularJS infrastructures - lazy loading techniques: 1. Introducing the lazy loading challenges with AngularJS 2. Review a working demo project

overview AngularJS encourage us to break our code into smaller pieces. Modules services directives controllers filters constants

overview Separating your code into multiple files considered a best practice when building large apps with angular. Angular seed project: js/ angular.module('myapp.controllers', []). controllers.js services.js directives.js filters.js partials/ partial1.html partial2.html controller('myctrl1', function() { }).controller('myctrl2', function() { });

overview We can define our modules as dependencies: angular.module('myapp',['ngroute', 'myapp.filters', 'myapp.services', 'myapp.directives', 'myapp.controllers', ngroute, ngresource, ui.bootstrap, ]).

overview but we must load all of our resources ahead: <script src="lib/angular.js"></script> <script src="lib/angular-route.js"></script> <script src="js/app.js"></script> <script src="js/services.js"></script> <script src="js/controllers.js"></script> <script src="js/filters.js"></script> <script src="js/directives.js"></script>.. <script src="lib/angular-resource.js"></script> <script src="lib/angular-bootstrap.js"></script> <script src="lib/underscore.js"></script>

overview All components must register against our module on bootstrap. otherwise we can't use them. Error: Argument mycontroller is not a function, got undefined register Lazy Loading Angular components

solution We need to answer those 3 questions in order to solve this challenge: How to lazy load scripts async? How to register our components against our module after bootstrap? When & where the actual loading occurs?

loading RequireJS provides a clean way to load and manage dependencies for our applications. <script data-main="main" src="require.js"></script> define(function () { // module code }) require([ module ], function (module) { // use this module }) http://requirejs.org/

register Components register against the module in the config phase using providers. For instance, we can register our controller manually using the $controllerprovider : angular.module('modulename', []).config(function($controllerprovider) { $controllerprovider.register('ctrl', function () { // controller code }) });

register All components can be registered with their matching provider methods: // services can register with $provide $provide.service() $provide.factory(), $provide.value(), $provide.constant(), // other components use specific providers $controllerprovider.resgister() $animateprovider.resgister() $filterprovider.resgister() $compileprovider.directive()

register we need to hold a reference to this provider in order to use it later in our code: var app = angular.module('modulename', []).config(function($controllerprovider) { app.loadcontroller = $controllerprovider.register; }) }); app.loadcontroller( somectrl, function ($scope) {})

when to load Where in the application should the actual loading take place? when routing to a view - $routeprovider when loading content - <ng-include> in response to event - like click or hover

routing The route object contain a resolve property that can accept a map of promises and wait for them to resolve before performing the route angular.module('modulename', []).config(function($routeprovider) { $routeprovider.when('/', { templateurl: 'view.html', controller : 'controller.js', resolve : // promise }) }) });

routing If every view managed by a controller we can reflect that in our project structure by packing them together & come up with naming conventions: views view-name view-name.html view-name.js.controller( viewnamectrl,. another-view another-view-name.html another-view-name.js

events We can load our dependencies as a reaction to an event. we can be creative and load our resources depending on the user behaviour: load only when a user start to fill a form load by mouse position load when a response comming back from the server

modules What about module loading? oclazyload is probably the best solution for lazy loading angular modules (for now): Dependencies are automatically loaded Debugger like (no eval code) The ability to mix normal boot and load on demand Load via the service or the directive Use your own async loader (requirejs, script.js...) https://github.com/ocombe/oclazyload

summary Lazy loading in Angular can be achived today with minimum effort. to keep our loading infrastructure flexible: 1. keep the loading logic in separated services this will make our life easier when this feature will be officially supported 2. use naming conventions this way developers can integrate more easily when moving between projects

summary Thank You! Demo project source code: https://github.com/nirkaufman/lazyloadingdemo