PDA

View Full Version : dynamic loading scripts



sagardash
1 Jul 2010, 4:23 AM
Hi

i want to know how to load scripts of extjs dynamically in a website while the user is idle...
i mean the user is reading something from one page that time i want to load the scripts in browser catch ...
so when the user proceed further at that time it will become speed up the loading...


I will really appreciate your help :)

THANKS

sagardash
1 Jul 2010, 7:13 AM
can any one please help me regarding this.......

Animal
1 Jul 2010, 7:15 AM
Just not NEARLY enough info.

If you want to create <script> elements, and have them loaded, then surely you must now how. It's basic HTML DOM manipulation which if you don't know, you shouldn't be attempting to write RIAs.

mschwartz
1 Jul 2010, 8:48 AM
I would use img tags myself, and you don't need to manipulate the DOM.

sagardash
1 Jul 2010, 10:44 PM
I want to know how to get the idle time means when the user not performing any transaction ...
may be user is reading something from website or filling any form... that time we can load the additional scripts ...
so that the further transactions of user will become speed up...

can we track that idle time..

THANKS

Animal
1 Jul 2010, 11:34 PM
Is this an ExtJS question?

Condor
1 Jul 2010, 11:49 PM
You could use Ext.Loader for that (ext-3.2.1/src/ext-core/src/core/Loader.js).

sagardash
2 Jul 2010, 1:13 AM
but i want find out some idle time.......
that time only those additional scripts should load ....

how to track out that idle time of website....

Condor
2 Jul 2010, 1:24 AM
Javascript is single-threaded. Idle time is anytime you don't have javascript to execute!

sagardash
2 Jul 2010, 3:17 AM
idle time in the sense when there is no http request is going from client to sever...
or when there is no transaction between server and client .. that time i want to track out...

can please help me

Condor
2 Jul 2010, 3:58 AM
You'll need to program this into your own code, because only your own code knows when it doesn't require any more server requests.

sagardash
2 Jul 2010, 4:42 AM
so there is no function to track out the time when there is no http request is going from client to server....

Condor
2 Jul 2010, 4:51 AM
You could use:

var delayedTask = new Ext.util.DelayedTask(function(){
// perform background loading
});
Ext.Ajax.on({
beforerequest: function(){
delayedTask.cancel();
},
requestcomplete: function(){
delayedTask.delay(5000);
},
requestexception: function(){
delayedTask.delay(5000);
}
});
(assumes you are using Ext.Ajax for all your requests)

mschwartz
2 Jul 2010, 5:11 AM
Put:



<div style="display: hidden">
<img src="script1.js" />
<img src="script2.js" />
... (more img)
</div>
</body>
</html>


The browser will load and cache your scripts at its leisure.

LoriSun
3 Jul 2010, 4:15 AM
Actually, I used the JIT for my js ondemend load...
And you want to catch the js in browser? I think this can setup in header, If the client side browser allowed.

mschwartz
6 Jul 2010, 5:07 AM
Again I read the first post.

He wants to load the JavaScripts (into browser cache) for the NEXT PAGE while the user is busy reading on the current one.

sagardash
7 Jul 2010, 3:28 AM
sorry i didnt get the solution till now....
is there any way to find out that time ?

i need the time when there is no transaction is going on between client and server.
like no xmlhttprequest is sending from client side...
or there is no interaction between client and server for max time...

please need help..

THANKS

Condor
7 Jul 2010, 5:59 AM
Is mschwartz correct? Are you trying to cache javascript for the next page?

sagardash
7 Jul 2010, 6:12 AM
yes

sagardash
7 Jul 2010, 6:15 AM
yes...
i want to load additional javascript to browser catch in the time time period when there is no xmlhttprequest is sending from client

Condor
7 Jul 2010, 6:28 AM
OK, so use the delayedTask example I posted above and load the additional .js file using Ext.Ajax.request (with disableCaching:false).

ps. Only one .js file I hope?

Elijah
7 Jul 2010, 8:22 AM
Why?
I mean seriously how big are your JavaScript files? Does it really slow down the page loads loading them?
And in regards to loading JavaScript files for the next page load, is this some sort of linear wizard app that the user can only go from the first page to a predetermined 2nd page?

I just dont see a benefit of spending time build the codebase to determine network inactivity and detect activity in order to save the loading of some JS files. Cost to benefit ratio I think the cost would outweigh the benefit.