Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Preload Images without Javascript?

In one of My Layout there are some large images (come from XML) which shown when I mouse hover on some some of the link, but when the Page loads and when i rollover It takes time to Load that Image.

Note: there are fix 5 images (not dynamic)

I dont want to use JavaScript to Preload Images any Solutions?

I am Not Using Hover menu or something like that, but this Images are Product Images and the links are Text link Got my Point??

like image 979
Wasim Shaikh Avatar asked May 04 '09 08:05

Wasim Shaikh


People also ask

Can you preload images?

Starting in Chrome 73, the browser can preload the right variant of responsive images specified in srcset before it discovers the img tag! Depending on your site's structure, that could mean significantly faster image display!

How do you preload images in CSS?

Preloading images using HTML <link> Tag. These two value options of rel (relationship between the current document and the linked document) attribute are most relevant with the issue: prefetch : load the given resource while page rendering. preload : load the given resource before page rendering starts.

Can you preload a div?

Since the DIV you're showing does contain background images these could be preloaded. All you need to do is use your normal preload script to load up the background image(s). Once the preload is complete you can fade-in the DIV.


2 Answers

HTML5 has a new way to do this, by link prefetching.

<link rel="prefetch" href="http://davidwalsh.name/wp-content/themes/walshbook3/images/sprite.png" /> 

Just add many link tags as you need in your HTML and you are good to go. Of course, older browsers will not load the content this way.

Note Above code will not work for Apple Safari safari does not support prefetch til now version 12 https://caniuse.com/#search=prefetch

UPDATE

If your server is served with HTTP2, you can also add a Link header in your response a made use of HTTP2 Server Push.

Link: <http://davidwalsh.name/wp-content/themes/walshbook3/images/sprite.png>; rel=preload; as=image; 
like image 118
Luis Dalmolin Avatar answered Sep 28 '22 02:09

Luis Dalmolin


From http://snipplr.com/view/2122/css-image-preloader

A low-tech but useful technique that uses only CSS. After placing the css in your stylesheet, insert this just below the body tag of your page: Whenever the images are referenced throughout your pages they will now be loaded from cache.

#preloadedImages {     width: 0px;     height: 0px;     display: inline;     background-image: url(path/to/image1.png);     background-image: url(path/to/image2.png);     background-image: url(path/to/image3.png);     background-image: url(path/to/image4.png);     background-image: url();  } 
like image 41
Khurram Aziz Avatar answered Sep 28 '22 02:09

Khurram Aziz