site design question on javascript

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

site design question on javascript

Post by m3rajk »

as is evident there's a bunch of javscript on my site. right now it's scatttered throught pages. i don't think anything is used more than one place at this point. but since i am adding some more, i was wondering about something. i figured asking those with more experience would be a good thing...

if i move all the javascript to an include file that gets included on all pages, would that have a signifigant affect on load time?

would it be something you would do or consider doing?

or would you only do this if you had functions reused in several pages and then only for that?

thanx in advance for your advice,
-Josh
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Really depends if I'm asked.

A 'bunch' can be rather much, and a byte is a byte so if you are including a 100 line .js file, yes the load time could differ alot.

This is really up to you alone (benchmarking time? ;)). I include mine just because it easier to maintain, but I don't think I have nearly as much javascript as you in my work.

Another loose untested idea is the below. Naming functions to match your page-names, and... well, you might get the idea behind it. This is focusing on having all javascript at one place, but only printing it when it is needed...

Code: Select all

// lib_java.php
function javascript_foo() {
 // return javascript here
}
function javascript_bar() {
 // return javascript here
}

---

// foo.php
if (function_exists('javascript_'.basename(__FILE__,'.php')) {
 // run that particular function..
}
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

i gathered everything.. i think, incase you'd like an example.. but now that it's gathered, only one non-inine thing would be useful outside of it's original place. so i guess unless i decide to add the character counting elsewhere it's better to keep it as is.
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

Might the .js file not be cached by the browser, reducing load time?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Yup, I'm thinking about first impression's counts high. Might not be an issue in this case tho.

I'm also one of alot of people I know of that doesn't use more than 3 days old cache.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

hmm.. i have cache set on "check against server every time"
Post Reply