Results 1 to 9 of 9

Thread: Dynamic load class

  1. #1

    Question Dynamic load class

    Hi, We are creating a new system with the possibilities to install some module. We are looking to load by ajax modules and class but we've got one problem... AJAX = async We can use wait, while(!done), serial load (one js, load by ajax another js wich load another js...) but these solutions aren't good (and for while(!done) really bad). We are looking to add js at the start of application by browsing the modules directory... by php... if you've got another solutions or code way... i'm really interesting. Thank's for help Romain DARY

  2. #2
    Sencha Premium User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258

    Default

    You have to do any processing in a callback:

    Code:
    Ext.Ajax.request({
        url: 'foo',
        success: function(response){
            // process the response
        }
    });

  3. #3

    Default So...

    10 diffrents js... = callback in callback in callback... no other way?

    Thanks for your answer

  4. #4
    Ext JS Premium Member
    Join Date
    Apr 2010
    Posts
    51

    Default

    I don't know if this is easy or not but i was hoping ot be able to load a class defintion when someone clicks a button. For instance, click the button and a window appears. This would include several classes that I would want to load.

    I'm just trying to avoid having to load all my classes for less used functions.

    Is there a standard way to do this?

  5. #5
    Sencha User
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    I do not recommend this. Including all classes in a single concatenated, minified and gzipped javascript file is almost always faster.

  6. #6
    Ext JS Premium Member
    Join Date
    Apr 2010
    Posts
    51

    Default

    I really appreciate your input and I can understand this is true in many cases but as the application grows this becomes more of an issue.

    In several circumstances I have resources that wont be used during many use cases. So for instance I have an extensive help system that consists of 10-15 classes. Unless someone clicks the Help button why would I want to load those classes? It slows down my load and eats memory. It just seems like large application design will require dynamic loading since the larger the application the more likely there will be paths some users will never go down. At some point loading it all up front isn't more efficient.

    At this point I'm asking "how can I", not "should I". After testing performance I can determine which is faster for my case. I appreciate for simple applications it makes sense but I may have hundreds of classes over time. I will try to break it up into separate pages where it is logical but there are plenty of cases where these "windows" share data and objects so it would be much easier and seamless to the user if I can dynamically load on demand.

    Obviously if testing proves that pre-load makes sense I'll go that way but I would like to at least test this unless the answer is there is no reasonable way to do it.

  7. #7
    Sencha User
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    Memory used by classes is not a real issue on current PCs and current browsers.

    The only thing that does matter is DOM size. Don't keep to many things rendered in the DOM. Remove components that you don't expect to be used often.

  8. #8
    Ext JS Premium Member
    Join Date
    Apr 2010
    Posts
    51

    Default

    Just FYI it looks like Ext.Loader does the trick. I was able to reduce my load time to almost zero and now I just load classes when someone pushes a button. I have almost 60 screens now but I only load the windows and related classes if they need them. Since we have several possible common paths through our system this makes sense since most people never need all of the code but someone will always need some of it. We could have implemented this as multiple web pages but this way I can seamlessly use objects between modules by having a single web page.

  9. #9
    Sencha User
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    But that would cause a lot of server requests.

    I think your app would be faster if you would concatenate, minify and gzip all the javascript you are using (including Ext) and load the entire .js file up front.
    For very large applications I could see the point in breaking the .js file into several (but not many!) functional parts (e.g. user vs. admin pages) and load on demand.

Similar Threads

  1. Replies: 2
    Last Post: 28 May 2010, 6:07 AM
  2. Loader class for dynamic loading of additional scripts
    By Fabyo in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 30 Apr 2010, 8:10 AM
  3. Dynamic class instances
    By martinrame in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 13 May 2009, 1:21 PM
  4. Class Ext.Button Dynamic tooltip
    By Mandeep in forum Sencha Ext JS Q&A
    Replies: 7
    Last Post: 23 Nov 2008, 7:49 PM
  5. Replies: 15
    Last Post: 1 May 2007, 2:14 AM

Posting Permissions

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