including/ importing javascript files

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

including/ importing javascript files

Post by kendall »

Hi,

I'm not a javascript pro or anything but....can you include/ import javascript files from within another javascript file?
User avatar
arjan.top
Forum Contributor
Posts: 305
Joined: Sun Oct 14, 2007 4:36 am
Location: Hoče, Slovenia

Re: including/ importing javascript files

Post by arjan.top »

http://ajaxpatterns.org/On-Demand_Javascript

look at DOM based on demand javascript :wink:
LSJason
Forum Commoner
Posts: 45
Joined: Mon May 12, 2008 4:43 pm

Re: including/ importing javascript files

Post by LSJason »

Code: Select all

 
document.writeln('<script src="LOCATION_OF_OTHER_FILE" type="text/javascript"></script>');
 
That may or may not work, depending on the rest of the code.
User avatar
HCBen
Forum Commoner
Posts: 33
Joined: Thu Jun 22, 2006 3:15 pm
Location: Indiana

Re: including/ importing javascript files

Post by HCBen »

If you don't mind using a js framework, check out mootools' Assets function: http://docs.mootools.net/Remote/Assets.js
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: including/ importing javascript files

Post by JAB Creations »

I always recommend not using a framework by default as a large portion of people surfing the internet are still using dial-up most especially here in the US where broadband providers don't feel obligated to wire customers who don't live in residentially concentrated areas. For example as much as I love jQuery when it's even compressed it will require about 8-10 seconds to load alone (in addition to your own work/images/etc).
User avatar
arjan.top
Forum Contributor
Posts: 305
Joined: Sun Oct 14, 2007 4:36 am
Location: Hoče, Slovenia

Re: including/ importing javascript files

Post by arjan.top »

8-10s?

so dial-up is 5KB/s? and jquery is 15KB, so it's 3 seconds and that is only the first time, javascript is loaded from cache on all the other requests
Post Reply