Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Can I make javascript load before images?

  • 22-04-2008 07:20PM
    #1
    Closed Accounts Posts: 238 ✭✭


    Hey,

    I've a photo gallery on a site that's using Lytebox (modification of Lightbox 2). It's working great except when the thumbnail image is clicked before all the thumbnails load...then it loads just the image without the Lytebox effect. This could be problematic for users with slow connections...

    Does the javascript need to be preloaded somehow? Can I set that to be ready before thumbnails are shown?

    Here's the gallery - follow through to an image.

    The script works by having the reference to the .js in the <head>...
    <script type="text/javascript" language="javascript" src="lytebox.js"></script>
    <link rel="stylesheet" href="lytebox.css" type="text/css" media="screen" />
    I've the styles added into my own stylesheet, don't think that matters though.

    Then adding the rel="lyteshow[album]" in the link from the thumbnail to the image file loads an album slideshow in lytebox...
    <a href="images/image-1.jpg" rel="lyteshow[album]" title="Image Description">Image #1</a>


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    You could try adding the Javascript source at the bottom of the page, thus making it the last element called for loading, but depending on the relative sizes of the script and image that may not make much difference.


  • Closed Accounts Posts: 238 ✭✭chat2joe


    ...thus making it the last element called for loading.....
    But would I not want it to be the first thing to be loaded?


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Dammit. I got the problem arseways :) Definately need sleep.


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    The DOM will need to be fully available before the JavaScript is triggered. One way to speed this up is

    1) Specify widths and heights for all elements
    2) Maybe (as a last resort) load a single transparent gif as the source for all image elements and swap it when the page is loaded.


Advertisement