Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript preload images

/* 
  Standards friendly image preloading
  Generates `<link rel="preload" as="image" href="important_image.png">`
  Ref: https://web.dev/preload-responsive-images/#preload-overview
*/
 
function preloadImages(images) {
  for (i = 0; i < images.length; i++) {
    let l = document.createElement('link')
    l.rel = 'preload'
    l.as = 'image'
    l.href = images[i]
    document.head.appendChild(l)
  }
}

// Usage:
imageUrlHeap = ['http://example.com/test/img-1.jpg','http://example.com/test/img-2.jpg','http://example.com/test/img-3.jpg'];
preloadImages(imageUrlHeap);
Comment

PREVIOUS NEXT
Code Example
Javascript :: object key value as string ts type js 
Javascript :: update node-modules 
Javascript :: javascript promise sleep 
Javascript :: Failed to transform react-native-reanimated-65.aar 
Javascript :: javascript-find-json-value 
Javascript :: cryptojs md5 get string 
Javascript :: find intersection of multiple arrays in javascript 
Javascript :: javascript detect mobile browser 
Javascript :: js code to generate random base64 code 
Javascript :: document.addEventListener("load", function () { 
Javascript :: create random hex in node 
Javascript :: wordpress echo admin ajax url 
Javascript :: react check if string is mail 
Javascript :: kb to mb javascript 
Javascript :: skip mongoose 
Javascript :: vue.js use scss in balise style 
Javascript :: select2 get selected value 
Javascript :: react import font awesome 
Javascript :: javascript remove src from img 
Javascript :: unique id generator 
Javascript :: how to clear nodemon cache 
Javascript :: bootstrap modal show jquery 
Javascript :: react native remove darkmode 
Javascript :: javascript remove element by id 
Javascript :: auto reload page javascript 
Javascript :: javascript remove from array by index 
Javascript :: concurrently node react 
Javascript :: window.location.href target blank 
Javascript :: readonly javascript 
Javascript :: install node js windows powershell 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =