DEV Community

Paul C. Ishaili
Paul C. Ishaili

Posted on

Ways to increase images load time speed on webpages / sites

  1. When loading a background image in a section or div of a website, it is neccessary to add an image tag within the div or section with a style display of none to increase the priority for the load time of that background image.
<header class = "hero" style="background-image: url(hero.jpg);"
   <img src = "hero.jpg" alt = "" style = "display: none" />
   <!-- Content -->
</header>
Enter fullscreen mode Exit fullscreen mode

The reason is because the browser won’t request the background-image until it knows it needs it, when the Render Tree is built and the Render Tree is only as fast as your slowest stylesheet. The above code snippet helps to get around it, by making the request start much earlier by simply moving it to your markup. HTML is fast because its declarative nature means it can be preload-scanned.

Sourced from: Harry Roberts' Tweet

Top comments (0)