+ Reply to Thread
Results 1 to 5 of 5

Thread: Preload background image

  1. #1
    Awesomexr's Avatar
    Awesomexr is offline x10 Sophmore Awesomexr is an unknown quantity at this point
    Join Date
    Dec 2008
    Location
    haslam.pcriot.com
    Posts
    118

    Preload background image

    I have tried various ways with javascript but none of them seem to work.

    The background-image is quite big, and it loads after the content. I want it to load before the content. How would i approach this?
    Last edited by Awesomexr; 12-23-2009 at 01:43 PM.

  2. #2
    marshian's Avatar
    marshian is offline x10 Elder marshian is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    526

    Re: Preload background image

    Why on earth would you want to do that?
    I'll give you two possible solutions:
    1. If you have an "enter" page, you could trigger loading the background image there. Code usable to "preload" an image on another page could be as follows:
    HTML Code:
    <img src="my_image.jpg" style="display: none;">
    2. Create a page with nothing on it, just the background image. Then use JavaScript to change the contents of the page when the page has loaded (body.onload). (Or use JavaScript to change the location to another page, using window.location.)

    But seriously, why do you want to do this? Perhaps there are better options than preloading the background image.

  3. #3
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

  4. #4
    suomiaol is offline x10Hosting Member suomiaol is an unknown quantity at this point
    Join Date
    Oct 2009
    Posts
    3

    Re: Preload background image

    Quote Originally Posted by Awesomexr View Post
    I want it to load before the content. How would i approach this?
    I think you could try jQuery. My suggestion is you insert a white/non-transparent overlay div on top of your page and let your background load behind it. Once the background is done loading hide the overlay div. Check out the event-load function on jquery.com: http://docs.jquery.com/Events/load

    Although, I'm trying to think how you could actually link the load function to a background image because your background image is declared in your CSS. Maybe you should have the overlay hide the whole page until whole window is done loading? Put a progress bar in the div and write e.g. loading to let your visitors know what is going on.

    Also you might want to try compressing your image to make it load *much* faster. You can compress images free online at imageoptimizer.net. I have a photo site and I always compress all large images because the #1 reason people will leave your site is if it takes too long to load.

  5. #5
    slacker3 is offline x10 Sophmore slacker3 is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    146

    Re: Preload background image

    Optimize all your images:
    http://www.pngoptimizer.com

    Saves 130k for the background image alone (still 233k..) without quality loss.
    Consider using just an small part of the image and x-repeat it, this will decrease load times dramatically.


    Giving it a second view, i've noticed you are using various image formats - it may be an good idea to convert them all to .png and use CSS sprites to reduce http requests. -> http://spritegen.website-performance.org
    Last edited by slacker3; 12-25-2009 at 02:59 AM. Reason: ...

+ Reply to Thread

Similar Threads

  1. removing image from background using photoshop cs3
    By sirtaylor1984 in forum Graphics & Webdesign
    Replies: 1
    Last Post: 05-15-2009, 09:54 AM
  2. Replies: 2
    Last Post: 03-12-2009, 12:54 AM
  3. Fixed background image
    By stalkio in forum Programming Help
    Replies: 3
    Last Post: 07-26-2008, 10:41 AM
  4. errors while attaching
    By mattspec in forum Feedback and Suggestions
    Replies: 0
    Last Post: 12-19-2005, 01:50 PM
  5. November Desktop
    By n4tec in forum Off Topic
    Replies: 12
    Last Post: 11-08-2005, 07:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers