Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8868267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:13:54+00:00 2026-06-14T17:13:54+00:00

Having read many preloading image using javascript title on internet, I found the same

  • 0

Having read many “preloading image using javascript” title on internet, I found the same solution.
Here is a simple sample code to preload a image with “stuff.jpg” name:

 <script>
    var img = new Image();
    img.src = "stuff.jpg"
 </script>

However I find no source telling me what actually the “src” property does when defining it (e.g img.src = “stuff.jpg”). My thinking here is, it’s just set “src” property to img by a string (that is “stuff.jpg”) and not loaded the real image yet.
But I am fairly reluctant about my thinking, because if it’s right, then the code above will be worthless.
Could you tell me what the src actually does in the above code and it would be great if you could give me a source for you explaination.
Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:13:55+00:00Added an answer on June 14, 2026 at 5:13 pm

    Yes, your code actually loads the image. Setting the src of an image object loads the image, now you just need to add the img to the DOM.

    Something like:

    var div = document.getElementById('theImg');
    div.appendChild(img);
    

    Of course doing it this way accomplishes nothing, but if the images are to be displayed in response to some event, a button click or something, then you actually pre-loaded the image.

    You can test this by executing your code in Chrome and looking at the Network tab in the Developer Tools and see that the image is actually requested from the server, even if you don’t add it to the DOM

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having read Joe Armstrong's book and watched Kevin Smith screencasts I've built a simple
I have read though many different examples but I am currently having difficulties trying
Having read the documentation and many many articles I believe the following should work
Besides having read all the posts about it in stackoverflow and many others, I
I'm having problems with updating a child model via nested form. I've read many
Having read many of Matthew Weier O'Phinney's posts regarding implementing ACL into Models, I
I have read many posts regarding detection of popup blocker by javascript code but
Having read this article and many others out there on how to not store
Simple question for all you pragmatic object-oriented fellas. I have read many times to
Hey I'm Having this problem in android project! I have read so many topics

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.