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
site design question on javascript
Moderator: General Moderators
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...
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?
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..
}-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC