: Is traditional JavaScript image pre-loading taboo I remember the good-old-days (not really) back when I was still sucking the teet of Dreamweaver to build websites and the lure of playing copypasta
I remember the good-old-days (not really) back when I was still sucking the teet of Dreamweaver to build websites and the lure of playing copypasta with fancy built-in scripts (ex, image-swap) was like black magic.
I'm pretty far removed from that now days but I was adapting a small site from it's original FrontPage (::cringe::) format to a standard HTML/CSS implementation and couldn't help wondering... should I should re-implement the JavaScript image pre-loading into the current version? Or, is there a better way?
I don't want to block the page from loading by requiring the user to request all the assets withing the page by using the traditional JavaScript pre-loader method. I value giving the user something to look at ASAP, and there's some potential harm to my Google mojo by doing so.
Is there a cleaner solution to prevent unnecessary page-reflows during loading? Such as, setting the static width/height dimensions through a CSS style attribute on the image element.
More posts by @Samaraweera270
2 Comments
Sorted by latest first Latest Oldest Best
Specifying image dimensions in HTML and/or CSS has always been recommended since the days of HTML 2.0, and eliminates the need for page reflows due to delayed image loading.
That takes care of static images. The other case is images that won't show up until after the page has loaded.
For simple things like rollover effects, you should be using background images and the CSS :hover selector, which AFAIK will be preloaded in most modern browsers. Or, better yet, use CSS sprites, which guarantee preloading and speed up image loading in general.
For more advanced things like image sliders, you do need some JavaScript. For those, when possible, I'd recommend using an existing script that will take care of preloading and other technical details in an efficient and well tested way.
Preloading images used in other pages can be done without interrupting current page loading. You can load the extra images after all the assets from the current page have finish loading.
Use the window.onload JavaScript event (or the $(window).load event if you use jQuery) to start loading the images needed to render the next page.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.