Code Monkey home page Code Monkey logo

angularjs-lazy-loading-with-requirejs-optimisation's Introduction

angularjs-lazy-loading-with-requirejs-optimisation (WIP)

A demonstration of lazy loading in AngularJS using RequireJS with r.js optimisation.

How to run the demo

  • Install node.js
  • Run npm install from within the root project directory to install relevant dependencies
  • Run grunt dev from within the root project directory to build the app into the app/dist folder. This is the folder that is served by the web server.
  • Run node server.js from within the root project directory to start the app
  • Navigate to http://localhost:3000/ in your browser

About r.js optimisation

r.js optimisation is done via grunt using the grunt-contrib-requirejs plugin. In this setup, all script files will be combined / optimized into two script files that are named as follows:

  • app.bootstrap.js: This will contain all vendor dependencies as well as any other code that is not specific to a given route.
  • xxx.dependencies.js: This will contain the dependencies for a given route, where 'xxx' is the name of the route.

When the app is initially accessed, it is these two script files that will be delivered to the browser. As the user then navigates to other routes, the lazy dependencies for the subsequent routes will either be delivered in individual downloads or as a single combined 'xxx.dependencies.js' file, depending on the 'optimize' flag found in xxx.state.config.js of each route, where 'xxx' is the route name. Allowing lazy dependencies to be delivered individually for subsequent route access (i.e., not the initial access of the site) ensures that dependencies that are shared amongst routes are not delivered to the browser multiple times. This ensures that bandwidth is not wasted. If no lazy dependencies are being shared between routes, or if loading a single optimized file will provide a significant improvement in speed regardless of some wasted bandwidth, then the 'opimize' flag of the route config can be set to 'true' to ensure that only a single file containing the combined dependencies is delivered to the browser when the user navigates to the route in question.

angularjs-lazy-loading-with-requirejs-optimisation's People

Contributors

ifyio avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.