PDA

View Full Version : Loading issue w/ script at bottom, or not?



chevy_ls_6
01-28-2011, 10:21 PM
I'm admittedly green in this area [among others!], but will there be any issues with any browsers loading the url below with the scripts at the bottom of the page like I have them?

http://alton.k12.mo.us/index.html

FF loads them fine for me, as does IE *until* I hit the compatibility mode button, then it seems to sort of "hang"...but with IE, I'm not really ever sure of what it's doing is correct or not?

Philip M
01-29-2011, 09:27 AM
window.addEventListener? Something wrong here!

There is no reason why scripts should not be loaded right ahead of the </body> tag, and some experts actually recommend that.


All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

gusblake
01-29-2011, 10:23 AM
Just posting to point out some odd programming practices:



if (daym<10)

daym="0"+daym

var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")


One-line control/conditional statements are usually put either all on one line, or with the code indented on the next line. Here they put in two linebreaks but no indentation, and then slightly indent the line after that.

Use of semicolons is random as far as I can tell.


function mydate(){

/*Current date script credit: JavaScript Kit (www.javascriptkit.com)*/

var mydate

And this only adds to the confusion.

chevy_ls_6
01-29-2011, 03:16 PM
window.addEventListener? Something wrong here!

There is no reason why scripts should not be loaded right ahead of the </body> tag, and some experts actually recommend that.


All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

LOL...I'm gonna guess that's wrong?! I couldn't tell ya, though...what do I need to do there? BTW, I love that signature!


Just posting to point out some odd programming practices:



if (daym<10)

daym="0"+daym

var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")


One-line control/conditional statements are usually put either all on one line, or with the code indented on the next line. Here they put in two linebreaks but no indentation, and then slightly indent the line after that.

Use of semicolons is random as far as I can tell.


function mydate(){

/*Current date script credit: JavaScript Kit (www.javascriptkit.com)*/

var mydate

And this only adds to the confusion.
I'm guessing the comment is in the middle of the function...?

I'd gladly accept any help on cleaning up that whole thing.

Philip M
01-29-2011, 03:34 PM
LOL...I'm gonna guess that's wrong?! I couldn't tell ya, though...what do I need to do there?

Remove that line!

if (daym<10)

daym="0"+daym

should be

if (daym<10) {daym="0"+daym}

and many other similar adjustments are desirable.


But as far as I can see the site works OK in IE. What do you mean by the "compatibility mode button"?

gusblake
01-29-2011, 04:45 PM
No don't remove that line, it's part of a ternary conditional that will throw a syntax error if that bit is removed. My advice would be to put these 3 lines...



window.addEventListener?

window.addEventListener('load',mydate,false):

window.attachEvent('onload',mydate);



...on the same line:


window.addEventListener?window.addEventListener('load',mydate,false):window.attachEvent('onload',myd ate);

Or change it to a simple if else:



if(window.addEventListener) {
window.addEventListener('load',mydate,false)
}

else if(window.attachEvent) {
window.attachEvent('onload',mydate);
}


If mydate is the only function you want to call you could always go with the cross-browser window.onload=mydate; and have done with it.

Philip M
01-29-2011, 04:53 PM
No don't remove that line, it's part of a ternary conditional that will throw a syntax error if that bit is removed. My advice would be to put these 3 lines...



Aarrggh! Yes, of course - I was totally mislead by the curious spacing. :(

chevy_ls_6
01-31-2011, 03:29 PM
Remove that line!

if (daym<10)

daym="0"+daym

should be

if (daym<10) {daym="0"+daym}

and many other similar adjustments are desirable.


But as far as I can see the site works OK in IE. What do you mean by the "compatibility mode button"?
In the latter versions of IE there's a "compatibility button" next to the refresh icon in the browser...from the IE site:

Compatibility View

Internet Explorer 8 is a new release and some websites may not yet be ready for the new browser. Click the Compatibility View toolbar button to display the website as viewed in Internet Explorer 7, which will correct display problems like misaligned text, images, or text boxes. This option is on a per site basis and all other sites will continue to display with Internet Explorer 8 functionality. When you click on the Compatibility View button for a site, you don’t need to do it again as the next time you visit that site the browser will show it in compatibility mode. If for some reason you’d like to go back to browsing with Internet Explorer 8 functionality on that site, simply click the Compatibility View button again.
Upon using that button, the site will only load 1/3 time I'd guess...but like I said, knowing IE, who knows exactly *what* it's trying to do.

No don't remove that line, it's part of a ternary conditional that will throw a syntax error if that bit is removed. My advice would be to put these 3 lines...



window.addEventListener?

window.addEventListener('load',mydate,false):

window.attachEvent('onload',mydate);



...on the same line:


window.addEventListener?window.addEventListener('load',mydate,false):window.attachEvent('onload',myd ate);

Or change it to a simple if else:



if(window.addEventListener) {
window.addEventListener('load',mydate,false)
}

else if(window.attachEvent) {
window.attachEvent('onload',mydate);
}


If mydate is the only function you want to call you could always go with the cross-browser window.onload=mydate; and have done with it.

That would be awesome...is it as simple as putting it in place of the above code?

The reason I asked about a loading issue is that my father has an older laptop running IE7.0.5 and it has trouble loading the site...granted, he's on a slow 256kbs connection, but that's the only computer/browser I've found that has trouble, but I was afraid there might be more.

gusblake
01-31-2011, 08:03 PM
Yes,



window.addEventListener?

window.addEventListener('load',mydate,false):

window.attachEvent('onload',mydate);


can be directly replaced by


window.onload=mydate;

If you will want to put other functions in later, do it like this:



window.onload=function() {
mydate();
//other_func(); etc.
}

chevy_ls_6
02-03-2011, 01:35 AM
Question: are all of the images (around 20) in the slideshow that lies wtihin the header being loaded entirely before loading the rest of the page? The reason I ask is I stopped by a computer with a slowish connection and it took forever for the page to render, and the div backgrounds within the page were the very last things to load?

gusblake
02-03-2011, 09:41 AM
I don't notice a difference when I turn javascript off; the page loads in 1 or 2 seconds either way. Have you tried clearing the cache and loading it a few times with javascript disabled on the slow machine?

chevy_ls_6
02-03-2011, 03:46 PM
I don't notice a difference when I turn javascript off; the page loads in 1 or 2 seconds either way. Have you tried clearing the cache and loading it a few times with javascript disabled on the slow machine?
No, but that's a good idea...:thumbsup: