Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

loading JavaScript files in run-time

Posted on 2011-09-21
7
Medium Priority
?
209 Views
Last Modified: 2012-05-12
Hi,

I have a very big JavaScript application with many JavaScript files.
It takes some time to load especially in new computers (first time the computer uses the app).
Is there something in JavaScript that I can load only the files that I use in the startup,
and then load the rest of the files on a "need to have basis" (when it is called)?
0
Comment
Question by:VapiSoft
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 15

Expert Comment

by:Eyal
ID: 36578520
sure you can.
use document.write to include new script files
don't forget to check if the function you want to activate is present before loading the js file
0
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 2000 total points
ID: 36578531
0
 

Author Comment

by:VapiSoft
ID: 36578543
1. I don't undertand how to do it?
2. Do I need to check every function before I use it? or is there something that can doit automatically?

For example: every time that it encounters an unresolved function (or variable) it will call a special function that will tell the browser what file to download.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 36578550
no, its just like making an ajax call, since when you make it, you need to go to call back handler to process the response
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 36578559
Eval: document.write does not work on demand.

Look at the function posted by Gurvinder to see how it's done
0
 
LVL 15

Expert Comment

by:Eyal
ID: 36578562
you can load the files you need with timer after the loading is completed

but it will be a good practice to check if the function exist before using it. let say the file didn't loaded yet

if (typeof functionname == 'function')

0
 

Author Closing Comment

by:VapiSoft
ID: 36578580
The trick at the end of the end of the second article (how to load only one) is great.
Thank you very much.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question