Problems with autoload of classes

83 views
Skip to first unread message

Sascha Herrmann

unread,
Oct 9, 2012, 4:47:43 PM10/9/12
to jsclas...@googlegroups.com
Hi!

Initially we tried to load our JS class files using JS.require() statements in the files itself, very much like Java import statements.

So if class X needs class Y to be loaded, we would put a "JS.require( "Y" ) into the file of class X. That did not work. We experienced hanging browser instances when we did that.

We removed all these spread statements and put all JS.require() statements into a sequence of calls in one JS function that is executed when our application renders to the client. We also use autoload rules very similar to the Songkick example.
But still we experience sporadic browser hangs (needs to be killed by task manager).

Probably, our JSF framework also has an effect. It loads and executes huge Javascript files during bootstrapping and that might interfere with the autoload?!

When we clear the browser cache, then the application starts in the browser. Maybe the loading time of the JSF framework gives the JSClass package manager more time to load and execute the scripts?!

We would need to load all JS class files in an easy way in one go before JSF framework's bootstrap loader can interfere. I had hoped that putting all JS.require() calls into one function would ensure that everything is loaded in one non-interruptible go, but that doesn't seem to be the case.

Any advice? How do we troubleshoot the hanging browser? Would the package-file-requires-provides way to load help us?

Thanks,

Sascha

James Coglan

unread,
Oct 13, 2012, 3:47:25 PM10/13/12
to jsclas...@googlegroups.com
On 9 October 2012 21:47, Sascha Herrmann <goo...@maledictis.de> wrote:
Initially we tried to load our JS class files using JS.require() statements in the files itself, very much like Java import statements.

We removed all these spread statements and put all JS.require() statements into a sequence of calls in one JS function that is executed when our application renders to the client. We also use autoload rules very similar to the Songkick example.
But still we experience sporadic browser hangs (needs to be killed by task manager).

Probably, our JSF framework also has an effect. It loads and executes huge Javascript files during bootstrapping and that might interfere with the autoload?!

When we clear the browser cache, then the application starts in the browser. Maybe the loading time of the JSF framework gives the JSClass package manager more time to load and execute the scripts?!

What I recommend you do is keep dependency information separate from the source code -- don't call JS.require() in source files, and express dependencies using JS.Packages config in a separate file.

When JS.require() loads your code, look in the console. Are there separate 'Loading' and 'Executing' lines, or do you see combined 'Loading and executing' lines? The former means the code is being downloaded with XHR then run using eval(), which might be slow.

It sounds like you might benefit from using the build tool to combine all your source into one file, rather than loading all of it asynchronously. Use this to combine all your app's code, and just include it with a script tag:

Colour Blend

unread,
Jun 8, 2013, 12:41:48 PM6/8/13
to jsclas...@googlegroups.com
Hello James,

How can i get it to do a combined 'Loading and executing'?

Regards,

Orson

James Coglan

unread,
Jun 8, 2013, 8:20:11 PM6/8/13
to jsclas...@googlegroups.com
On 8 June 2013 17:41, Colour Blend <sampso...@gmail.com> wrote:
How can i get it to do a combined 'Loading and executing'?

You can't control this, it depends on how the code is loaded. Code from the same origin is loaded via XHR and eval'ed, so downloading is separated from execution. Code from other origins is injected via script tags so these stages can't be separated, and that's when you see the message you described. 

Colour Blend

unread,
Jun 12, 2013, 6:09:53 AM6/12/13
to jsclas...@googlegroups.com
Hi James,

Thanks for the quick response.

I've been using JS.Class extensively for a while now and on a number of projects. I enjoy the package manager a lot. You admitted that the number requests can impact performance though it hasn't been an issue for you. However, i'm been beginning to notice some performance hit on the client side and i'm concerned.

You mentioned we can build/combine the scripts using the build tool described on you site. I'm using MVC 4, .NET 4.5, C# and Visual Studio;

1. How can i use this build tool in .Net and Visual Studio
2. How can i integrate it with Visual Studio
3. How easy will it be to continuously build the scripts during development to maintain a good level of productivity.

Thanks in advance.

Regards,

Orson

James Coglan

unread,
Jun 12, 2013, 12:14:34 PM6/12/13
to jsclas...@googlegroups.com
On 12 June 2013 11:09, Colour Blend <sampso...@gmail.com> wrote:
You mentioned we can build/combine the scripts using the build tool described on you site. I'm using MVC 4, .NET 4.5, C# and Visual Studio;

1. How can i use this build tool in .Net and Visual Studio
2. How can i integrate it with Visual Studio
3. How easy will it be to continuously build the scripts during development to maintain a good level of productivity.

I'm afraid I don't know anything about the .NET platform. What I do know is that you could use a file-tree monitor like https://npmjs.org/package/watch to watch your project for changes and use that to run `jsbuild` whenever your source code changes. 

Colour Blend

unread,
Jun 12, 2013, 1:28:08 PM6/12/13
to jsclas...@googlegroups.com
Thanks. I hopefully will find a way out.
Reply all
Reply to author
Forward
0 new messages