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 7496991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:53:02+00:00 2026-05-29T18:53:02+00:00

I have a javascript widget which indicates the server status with alarm LED picture.

  • 0

I have a javascript widget which indicates the server status with alarm LED picture. The picture is selected by applying appropriate class to DOM element with appropriate style in CSS defined.

The problem is that when server is down, it is unable to provide image file for the style. So, my button just appears empty.

The question is: how to preload the image to browser cache so it can and would display it when server is down?

  • 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-05-29T18:53:03+00:00Added an answer on May 29, 2026 at 6:53 pm

    You can preload the image by creating an img element and assigning the path to the src:

    var img = document.createElement('img');
    img.src = "/path/to/image";
    

    That’ll put it in cache. I don’t think you even have to put it in the DOM for the browser to load it, but if you want to be absolutely sure, you can do this:

    img.style.position = "absolute";
    img.style.left = "-10000px";
    document.body.appendChild(img);
    

    That loads it, but off-page where the user won’t see it. It might even be best to do that with whatever element you’re actually displaying the image on, and then just move the element to where you need it to be when displaying it, to avoid having the browser send a new GET with an If-Modified-Since when you’re showing it, but in theory if your cache headers are correct the browser shouldn’t want to.

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

Sidebar

Related Questions

We have a widget which is inserted via Javascript. <div class=tp_-_box data-tp-settings=domainId:7913 hidden> <a
I have a JavaScript widget which provides standard extension points. One of them is
I have a JavaScript widget which communicates with my Rails app by creating tags
http://jsfiddle.net/4B2Bc/1/ <- the link to the widget I have this javascript widget, which I
Given an html/javascript 'widget' which needs to have certain fields customized before use. For
Lets say you have a JavaScript widget which needs to fire off a request
I have some javascript which will create some sort of widget on a page.
I have a JavaScript widget that is hosted on websites. This widget tracks state
We have a UI widget on our main UI that uses JavaScript to respond
I have JavaScript code which copies the value of input file and paste it

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.