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.
|
|
|
|
|
![]() |
||
Forcing JavaScript to load before images?
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
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
Is there any way I can force the script to be loaded before the images in order to avoid this problem? Thanks, Jenny |
|
|
|
#2
|
|||
|
|||
|
Re: Forcing JavaScript to load before images?
Is the script in the head section of your page?
__________________
Web Design and Development |
|
#3
|
|||
|
|||
|
Re: Forcing JavaScript to load before images?
Hi Scott,
the header contains (in this order)
Thanks for your advice, Jenny |
|
#4
|
||||
|
||||
|
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)
|
|
#5
|
|||
|
|||
|
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?
|
|
#6
|
||||
|
||||
|
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. |
|
#7
|
|||
|
|||
|
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
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. |
|
#8
|
|||
|
|||
|
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 |
|
#9
|
|||
|
|||
|
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 |
|
#10
|
|||
|
|||
|
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.
|
|
#11
|
|||
|
|||
|
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 |
|
#12
|
|||
|
|||
|
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. |
|
#13
|
|||
|
|||
|
Re: Forcing JavaScript to load before images?
Cheres pete, may look into that at some point
|
|
#14
|
|||
|
|||
|
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 |
|
#15
|
|||
|
|||
|
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. |
![]() |
| Tags |
| image gallery, javascript, thumbnails |
| Thread Tools | |
|
|
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 |