www.webdeveloper.com
Results 1 to 8 of 8

Thread: [RESOLVED] Preload images checkup

  1. #1
    Join Date
    Aug 2012
    Posts
    43

    resolved [RESOLVED] Preload images checkup

    Hi everyone,
    I'm just wandering if the following script is sufficient to preload my images...

    number_of_images is actually a variable but for clearness i removerd the php code.

    Code:
    // create image object
    preload_image_object = new Image();
    
    // set image url array
    image_url = new Array();
    
    // fill image url array
    var x = 0;
    for(x=0; x<number_of_images; x++){
    	image_url[x] = "images/image_" + x + ".jpg";
    	preload_image_object.src = image_url[x];
    }
    maybe one of you guys want to check the effectiveness?

    Thanx!
    Last edited by Nomistake; 08-26-2012 at 05:43 AM.

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    It is not correct. You need an Image object for each image, you can't re-use the same one.

    The simplest way is this, as long as you don't intend to refer to the Image objects later:
    Code:
    for( var x = 0; x < number_of_images; x++)
       new Image().src = "images/image_" + x + ".jpg";
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  3. #3
    Join Date
    Aug 2012
    Posts
    43
    thank you very much.

    so i have this now:

    Code:
    var x = 0;
    for(x=0; x < number_of_images; x++){
    	new image().src = "images/image_" + x + ".jpg";
    }
    am i right i only needs this to make sure the images are already in the cache of the explorer?
    and then later on they are called bij an <img> object which should show the already cached image... ?
    just to be sure
    Last edited by Nomistake; 08-26-2012 at 12:54 PM.

  4. #4
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by Nomistake View Post
    am i right i only needs this to make sure the images are already in the cache of the explorer?
    and then later on they are called bij an <img> object which should show the already cached image... ?
    If by 'later on' you mean when another script subsequently loads them into an <img> placeholder, then yes.
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  5. #5
    Join Date
    Aug 2012
    Posts
    43
    Well, by 'later on' i mean displaying them like this:
    <img src="images/image_1.jpg" alt="image_1">
    <img src="images/image_2.jpg" alt="image_2">
    etc...
    So it will use the cached?
    ___________________________________
    another thing thats comes to my mind:

    the thing is, depending on which menu item is clicked, the images folder kan be different, but the sequence of the image names remains the same... :

    Code:
    var x = 0;
    for(x=0; x < number_of_images; x++){
    	new image().src = "projects/image_" + x + ".jpg";
    }
    is this a problem?
    will the image \images\image_1.jpg be in cache automatically be overwritten by \projects\images_1.jpg

    sorry for al my questions but as you can see, i'm rather new to this

    Thank you for your time!
    When the only tool you have is a hammer, everything looks like a nail.

  6. #6
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by Nomistake View Post
    Well, by 'later on' i mean displaying them like this:
    <img src="images/image_1.jpg" alt="image_1">
    <img src="images/image_2.jpg" alt="image_2">
    etc...
    So it will use the cached?
    No, pre-loading images that are to be displayed initially is pointless.

    will the image \images\image_1.jpg be in cache automatically be overwritten by \projects\images_1.jpg
    No.
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  7. #7
    Join Date
    Aug 2012
    Posts
    43
    Wel, they are not displayed initially,
    it's like a photo/image slide show.

    with the above code, i preload the images that will be displayed when the user advances trough the slide show... of course i don't display them directly on the first page :-)

    so i hope my code isnt pointless?

    greetings,
    When the only tool you have is a hammer, everything looks like a nail.

  8. #8
    Join Date
    Aug 2012
    Posts
    43
    When the only tool you have is a hammer, everything looks like a nail.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.14449 seconds
  • Memory Usage 2,924KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (4)bbcode_code
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (8)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates