DEV Community

Paul C. Ishaili
Paul C. Ishaili

Posted on

5 1

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)

Eliminate Context Switching and Maximize Productivity

Pieces.app

Pieces Copilot is your personalized workflow assistant, working alongside your favorite apps. Ask questions about entire repositories, generate contextualized code, save and reuse useful snippets, and streamline your development process.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay