Forcing JavaScript to load before images?

This is a discussion on "Forcing JavaScript to load before images?" within the Starting Out section. This forum, and the thread "Forcing JavaScript to load before images? are both part of the Design Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Design Your Website > Starting Out

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jul 9th, 2007, 21:00
Junior Member
Join Date: Jul 2007
Location: South Coast
Age: 35
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Forcing JavaScript to load before images?

Hi,

I have just designed a website which uses the Dynamic Drive Image Thumbnail Viewer. If a visitor clicks on one of the links, the full-size image is superimposed over the page.

Everything worked fine locally because of the short loading times for the thumbnails. Now that the site is online, I have the problem that if I click on a thumbnail before all other thumbnails are loaded, the attribute

Code: Select all
rel="thumbnail"
in the <a> tag isn't recognised (I assume because the script hasn't been loaded yet) so that it is ignored and the image loads on a new page.

Is there any way I can force the script to be loaded before the images in order to avoid this problem?

Thanks,

Jenny
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jul 11th, 2007, 01:23
Reputable Member
Join Date: Dec 2005
Location: U.S.A.
Posts: 155
Thanks: 0
Thanked 4 Times in 4 Posts
Re: Forcing JavaScript to load before images?

Is the script in the head section of your page?
__________________
Web Design and Development
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jul 11th, 2007, 08:01
Junior Member
Join Date: Jul 2007
Location: South Coast
Age: 35
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Forcing JavaScript to load before images?

Hi Scott,

the header contains (in this order)
  1. a <link> tag for an external stylesheet
  2. a <link> tag for the stylesheet accompanying the thumbnail viewer
  3. a <script> tag for including the thumbnailviewer.js
  4. a <style> tag for the internal styles
Should I change the order?

Thanks for your advice,

Jenny
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jul 11th, 2007, 21:43
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Forcing JavaScript to load before images?

No expert...
but shouldn't you just swap 3 and 4 around?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jul 12th, 2007, 11:39
Reputable Member
Join Date: Jun 2007
Location: UK
Age: 29
Posts: 172
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Forcing JavaScript to load before images?

I am not a javascript expert, but could you call the javascript with onload in the body tag?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Jul 12th, 2007, 12:57
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Forcing JavaScript to load before images?

There really isn't a good way to get around this. While the way you have your site coded as of now may seem a bit buggy if the page hasn't finished loading, it is necessary because 5% of people browse the internet with JS disabled (meaning they'll need a link to see the full images).

Reducing the number of thumbnails per page or loading them dynamically (Like Lightbox or another Ajax script) would be the best way to improve the issue.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Jul 12th, 2007, 13:39
Junior Member
Join Date: Jul 2007
Location: South Coast
Age: 35
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Forcing JavaScript to load before images?

I don't quite understand that. If there was a way to preload the script into the browser cache before everything else is loaded, I would still have the links - surely if someone had JavaScript disabled, only the 'rel' attribute in the <a> tags would be ignored and the image would simpy open on a new page (obviously not ideal as a visitor would have to hit the 'back' button to return to the page with the thumbnails but better than not being able to see the full-size images at all)?

I must admit, I have never written a single line of JavaScript in my life, but from looking at the code inserted by DW if I add rollovers, I have been able to figure out
  1. how the function is defined which preloads the images
  2. how this function is called from the body tag through the onLoad attribute
Isn't there a similiar way in which the script can be preloaded before the content of the page is displayed?

Thanks,

Jenny

P.S.: I've looked at Lightbox - looks good to me, so if there isn't a solution for my problem, I'll go for that one instead.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Jul 12th, 2007, 21:46
Reputable Member
Join Date: Dec 2005
Location: U.S.A.
Posts: 155
Thanks: 0
Thanked 4 Times in 4 Posts
Re: Forcing JavaScript to load before images?

Hello Jenny,

Looks like you have found a good solution. But I feel it's important for you to know for future reference that everything in the head section is read and loaded first. So your script is loaded before the page, but the images are not.
__________________
Web Design and Development
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Jul 12th, 2007, 22:15
Junior Member
Join Date: Jul 2007
Location: South Coast
Age: 35
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Forcing JavaScript to load before images?

Thanks Scott.

I'll be trying that. I guess that will motivate me to learn some JS if I see the script each time I open the HTML file...

Cheers & good night,

Jenny
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Jul 13th, 2007, 10:14
Reputable Member
Join Date: Jun 2007
Location: UK
Age: 29
Posts: 172
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Forcing JavaScript to load before images?

Yeah I would like to learn it properly too. I can modify scripts and implement them, but not really make them from the start. I guess thats how you learn. I think one of the things that has put me off is the fact that its client side and not everyone has it installed. Still theres some things JS does that you cant do with server side scripting.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Jul 13th, 2007, 11:43
Junior Member
Join Date: Jul 2007
Location: South Coast
Age: 35
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Forcing JavaScript to load before images?

I totally agree. I am getting more and more requests from people who want me to design their sites and JavaScript is definitely on my 'to-learn' list although it's not the highest priority - I'll rather be focusing on improving my Photoshop skills, building up on my existing PHP knowledge and start learning Flash.

Looking forward to it and I'm really pleased to have found this forum to get some support whenever I get stuck with anything.

Jenny
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Jul 13th, 2007, 12:03
Most Reputable Member
Join Date: May 2006
Location: North West, UK
Age: 22
Posts: 1,173
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Forcing JavaScript to load before images?

JS is a great tool to have but its so important to learn the right way. For me all JS/AJAX stuff should be implemented with every user in mind. Progressive Enhancement cannot be overlooked, everything should work whether JS is on or off.

I recommend DOM Scripting by Jeremy Keith if anyone is interested in learning from scratch. It's all clever stuff.

Pete.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Jul 13th, 2007, 13:31
Reputable Member
Join Date: Jun 2007
Location: UK
Age: 29
Posts: 172
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Forcing JavaScript to load before images?

Cheres pete, may look into that at some point
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Jul 13th, 2007, 22:51
Reputable Member
Join Date: Dec 2005
Location: U.S.A.
Posts: 155
Thanks: 0
Thanked 4 Times in 4 Posts
Re: Forcing JavaScript to load before images?

Yet, another note if you are thinking that JS is not a high priority. The amount of people that actually have JS turned off is minimal. And there are many things that are more efficient to run on the client side before you fire up your server side and/or database.

That being said, it is important to keep in mind that some people do have JS disabled... so design your pages/applications with that in mind.
__________________
Web Design and Development
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old Jul 13th, 2007, 23:02
Most Reputable Member
Join Date: May 2006
Location: North West, UK
Age: 22
Posts: 1,173
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Forcing JavaScript to load before images?

Depends who your site is targeted at. I know a lot of companies have JS disabled for security reasons (I assume) so anything that maybe accessed by people who work in an office etc should probably not make too much use of it. That said it is such a valuable tool and all these RIA's wouldn't be possible without it.

AJAX (or perhaps HIJAX?) all the way!

Pete.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
image gallery, javascript, thumbnails

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
load javascript file VanHype JavaScript Forum 7 Apr 27th, 2007 15:00
How to ensure important images load first? snappy Web Page Design 16 Nov 15th, 2006 15:14
How to use a javascript variable to load an image VanderBOOM JavaScript Forum 2 Nov 13th, 2006 14:00
HELP!!! Images won't load IE 6 Lilas Graphics and 3D 1 Dec 23rd, 2005 18:08
Pre-Load Images WiseWizards JavaScript Forum 25 Jul 20th, 2005 17:28


All times are GMT. The time now is 03:37.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42