Results 1 to 7 of 7

Thread: The best way to load scripts dynamically (Extjs 3.3.1)

  1. #1
    Sencha User
    Join Date
    Mar 2010
    Location
    Utrecht, NL
    Posts
    15

    Question The best way to load scripts dynamically (Extjs 3.3.1)

    Hi there,

    You could say i'm quite a beginner, but not a newbie. However JS in general is not my strongest point.
    I have an application which should load scripts dynamically. What is the best way to do so currently?

    I have structured the application like this:
    MyApp.js
    which loads: MyPartialAppOne.js
    which loads: AppOne_grid.js, AppOne_tabpanel.js, and some more

    I know this option:
    Code:
    function AddScript(script) {
    var ScriptTag = document.createElement('script'); ScriptTag.setAttribute("type","text/javascript") ScriptTag.setAttribute("src", script); document.getElementsByTagName("head")[0].appendChild(ScriptTag);
    }
    However I never know if it's loaded right, and de console doesn't get any errors from scripts loaded
    by a dynamically loaded file.

    Any suggestions where to look? I've been searching, so I either didn't recognize the right thread or
    page, or it isn't there.

    Thanks in advance for any reply.

  2. #2
    Sencha User fay's Avatar
    Join Date
    Apr 2007
    Location
    Ireland
    Posts
    1,750

    Default

    Have you looked at Ext.Loader? (As suggested in the "Similar Threads" below)

  3. #3
    Ext User
    Join Date
    Dec 2010
    Location
    Czech Republic
    Posts
    5

    Default

    Look at Jingo module manager: http://code.google.com/p/jingo/wiki/GettingStarted. It manages inter-module dependencies too.

  4. #4
    Sencha User
    Join Date
    Mar 2010
    Location
    Utrecht, NL
    Posts
    15

    Default

    @fay:
    Jeez, my first reaction was: "How blind can I be?".
    The actual answer was: the search option in de documentation doesn't provide this as an searchresult.
    Bit weird, or is that normal?

    @kalab:
    I've just jumped into ExtJS. A quick peek makes this look like some other kind of framework. Maybe you could
    explain a bit more (especially for future referrence, not for me though )

    Thanks both for the quick answers.

  5. #5
    Sencha User fay's Avatar
    Join Date
    Apr 2007
    Location
    Ireland
    Posts
    1,750

    Default

    You're right Peter, the API search isn't returning it. I've found this to be true of a couple of other ones as well (ButtonGroup and FlashComponent to name two). The thing about being "blind to it" is that the "Similar Threads" obviously can't come up until you've posted your question...

  6. #6
    Ext User
    Join Date
    Dec 2010
    Location
    Czech Republic
    Posts
    5

    Default

    I currently use Jingo as a module loader for my application. It does not depend on a specific JS framework, uses only clear JS/JSON syntax for module declaration.

    for example:

    - define module with dependencies:
    Code:
    jingo.declare({
       name: "module1",
       require: ['module2', 'module3'],
       as: function(){
          App.Modules.module1 = function(){
             return {
                action: function(){
                    window.alert('I am module 1');
                }
             };
          }();
       }
    });
    - use the module:

    Code:
    jingo.anonymous({
      require: ["module1"],
      exex: function(){
        App.Modules.module1.action();
      }
    });
    It looks up for modules in a preconfigured location, automatically declares namespaces by the module name, uses specific module pattern as interface.

  7. #7
    Ext User
    Join Date
    Dec 2010
    Location
    Czech Republic
    Posts
    5

Similar Threads

  1. dynamically loading scripts ?
    By muncher in forum Ext 3.x: Help & Discussion
    Replies: 3
    Last Post: 11 Oct 2010, 8:34 AM
  2. Replies: 2
    Last Post: 30 May 2008, 4:30 AM
  3. Debugging dynamically loaded scripts
    By faridadhami in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 3 Apr 2008, 5:11 AM
  4. Dynamically Loading and removing Scripts
    By boriscy in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 29 Feb 2008, 1:40 PM
  5. How to load less scripts from Extjs
    By saganxis in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 15 Feb 2008, 10:34 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •