Git Product home page Git Product logo

Comments (6)

CaryLandholt avatar CaryLandholt commented on May 10, 2024

Leif,

The shim configuration simply sets up the dependencies for any module that may be loaded.
These modules do not get loaded unless they are requested.

The next section, within the array, are the modules that are being requested.

So, if we have

require
    shim:
        'controllers/gitHubController'       : deps: ['app', 'services/gitHubService']
        'controllers/personController'       : deps: ['app', 'services/personService']
        'controllers/personDetailsController': deps: ['app', 'services/personService']
        'controllers/searchHistoryController': deps: ['app', 'services/messageService']
        'directives/ngController'            : deps: ['app']
        'directives/tab'                     : deps: ['app']
        'directives/tabs'                    : deps: ['app', 'directives/tab']
        'filters/twitterfy'                  : deps: ['app']
        'libs/angular-resource'              : deps: ['libs/angular']
        'responseInterceptors/dispatcher'    : deps: ['app']
        'services/gitHubService'             : deps: ['app', 'services/messageService']
        'services/messageService'            : deps: ['app']
        'services/personService'             : deps: ['app']
        'app'                                : deps: ['libs/angular', 'libs/angular-resource']
        'bootstrap'                          : deps: ['app']
        'routes'                             : deps: ['app']
        'run'                                : deps: ['app']
        'views'                              : deps: ['app']
    [
        'require'
        'controllers/gitHubController'
    ], (require) ->
        angular.element(document).ready ->
            require ['bootstrap']

Only the gitHubController is requested to be loaded.
Following the dependency chain, the following will be loaded.

  • controllers/gitHubController
  • app
  • libs/angular
  • libs/angular-resource
  • services/gitHubService
  • services/messageService

Notice that personService, routes, views, and others are not loaded. They are defined (configured) in the shim section, but in the sample above are not loaded.

require is requested so after the modules are loaded we can request bootstrap. When loading modules asynchronously, bootstrap needs to be called last. Requesting it in the callback ensures it is last.

I hope this helps.

Thanks,
Cary

from angularfun.

jwall avatar jwall commented on May 10, 2024

Thank you for this project and for the further explanation of main.coffee.

What if I wanted to include some third party js that is using jquery? Do I include it directly in the index template or ?

from angularfun.

jwall avatar jwall commented on May 10, 2024

Including it in the index template does work. The best way is to angularize everything, but in lieu of that, direct index inclusion does work.

from angularfun.

bkak avatar bkak commented on May 10, 2024

In the sample it loads all the scripts in the browser. Does this application load javascript(eg personController,PersonService etc) when required or I am missing something.

from angularfun.

CaryLandholt avatar CaryLandholt commented on May 10, 2024

Hey @bkak,

Yes the JavaScript files are loaded as-needed via RequireJS.
Keep in mind this is only necessary in the dev build. The prod build compiles everything into one file and doesn't need this functionality.

Thanks,
Cary

from angularfun.

CaryLandholt avatar CaryLandholt commented on May 10, 2024

@jwall,

Including jQuery with AngularJS apps requires jQuery to load prior to AngularJS.
Certainly the easiest way is to add jQuery to the index.html file.
RequireJS does provide the ability to include external files via its configuration, however.

Thanks,
Cary

from angularfun.

Related Issues (20)

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.