Which takes longer to render: individually drawn images placed via absolute positioning, or one complete image?

I currently have a collection of "cards" on my website that are jpg images, but I am considering switching to an HTML/CSS solution. This change would involve placing numerous small icons on a background and adding stylish text on top.

My concern is determining which method is faster for both the client and the server.

To help illustrate this dilemma, I quickly put together a rough example.

Original full image size is 111kb:

https://i.sstatic.net/jD2av.jpg

Rendering using HTML/CSS:

Check out the code here

<div class="wrapper">
  <img class="background" src="http://i.imgur.com/qCxyd9v.jpg">
  <img class="icon one" src="http://i.imgur.com/c5Qx3x7.png">
  <img class="icon two" src="http://i.imgur.com/4G8xUeM.png">
  <img class="icon three" src="http://i.imgur.com/9Kips1U.png">
  <img class="icon four" src="http://i.imgur.com/0utE9VD.png">
  <img class="icon five" src="http://i.imgur.com/Ej7w0pA.png">
  <img class="icon six" src="http://i.imgur.com/9EdnWnW.png">
  <div class="text">
    How can I measure the performance impact of this rendering approach?
  </div>
</div>

.wrapper {
  position: relative;
}
.icon {
  position: absolute;
}

.icon.one {
  left: 10px;
  top: 20px;
}

.icon.two {
  left: 140px;
  top: 20px;
}

.icon.three {
  left: 270px;
  top: 20px;
}

.icon.four {
  left: 400px;
  top: 20px;
}

.icon.five {
  left: 140px;
  top: 150px;
}

.icon.six {
  left: 270px;
  top: 150px;
}

.text {
  position: absolute;
  left: 120px;
  top: 350px;
  font-size: 24px;
  color: white;
  text-align: center;
  max-width: 300px;
}

The background image size is 73 kb, with each icon being 7kb, totaling to 115 kb.

Sometimes, some of the icons may be duplicates, reducing the overall file size. However, it's essential to consider the cost of positioning elements on the page.

How can I accurately measure the most efficient option? It seems like a case-by-case evaluation rather than a straightforward answer.

So, should I:

1) Figure out how to measure the best choice?

or

2) Accept that it doesn't make much difference in the end?

Answer №1

After conducting a measurement on your fiddle using Chrome Dev Tools, I have provided a screenshot for reference.

https://i.sstatic.net/reg4o.jpg

The approach of fragmenting the image into separate assets appears to be advantageous as it leads to numerous concurrent http requests, which is typically more efficient with the same bandwidth.

It's worth noting that in cases like this, determining a universal rule can be challenging and decisions may need to be made on a case-by-case basis.

For this specific scenario, I recommend employing the "many-assets-via-css" method.

Answer №2

Are you curious about how to measure the loading time of a website? Well, all you need is an inspector tool. I recommend using Google Chrome and accessing the inspector, then navigating to the "Timeline" tab. From there, refresh the page or click record in the top-left corner before refreshing to view load times for different elements.

For instance, this particular page loads in 2.72 seconds with specific breakdowns like 77.11ms Loading, 456.61 Scripting, 191.89 Rendering, 162.97 Painting, and 163.16 Other. By analyzing these metrics, you can identify the major areas affecting your page's performance. In this case, scripting seems to be the biggest pain point, but it only causes a half-second delay, so nothing major to worry about.

If your file sizes are minimal and if there aren't multiple repetitive items on the page, they won't significantly impact loading time. A 115kb main file plus a typically small CSS size should not pose a noticeable delay on most modern devices. However, increasing the number of images can lead to more significant loading issues. In such cases, consider combining and optimizing images to reduce server calls.

UPDATE Check out this crude example demonstrating how to use a single icon with CSS to create diamond shapes: https://jsfiddle.net/g4stvufk/

Ensure that the icon includes the diamond shine effect for authenticity.

HTML

<div class="diamond">
    <img src="http://i.imgur.com/PWeXerY.png">
</div>

CSS

.diamond {
    width: 0;
    height: 0;
    border: 65px solid transparent;
    border-bottom-color: red;
    position: relative;
    top: -50px;
}
.diamond:after {
    content: '';
    position: absolute;
    left: -65px;
    top: 65px;
    width: 0;
    height: 0;
    border: 65px solid transparent;
    border-top-color: red;
}
img {
    position: absolute;
    top: 60px;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1;
}

The key advice here is to "Reuse, Reuse, Reuse." Utilize existing resources whenever possible, like reusing icons and effects to improve efficiency.

Answer №3

Optimizing website performance involves minimizing http requests, such as by implementing image sprites which require only one request and utilizing CSS for positioning. Automation tools like Grunt or Gulp can help streamline this process, including the use of lossless compression tools like TinyPNG.com to reduce image file sizes (these can also be integrated as API calls within your automated tasks), providing a comprehensive solution.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieving PNG image from dynamically created PDF file with DomPDF

Having trouble displaying an image on a generated PDF using DOMPDF. My DomPDF version is v2.0.3 and I'm working with XAMPP on localhost. This is the output: see image here Below is the code snippet: <?php require_once __DIR__ . '/vendor/auto ...

Using jQuery to toggle the visibility of div elements while displaying an indicator

A query arises regarding the utilization of JQuery to facilitate toggling the visibility of text divs. The question pertains to how one can incorporate an indicator - such as an up and down arrow graphic - to denote whether the divs are open or closed. Sug ...

What is the process for integrating SAP BO objects into HTML containers?

Has anyone successfully integrated a SAP BO object into an HTML container? I'm looking to embed a dashboard directly onto my webpage instead of redirecting users to a new tab for the Business Objects platform. ...

Embracing JQuery for Frontend Development with Node.js

I'm currently enhancing my node.js skills by utilizing express, and I've encountered a situation that is causing me some confusion. Essentially, when a user requests a webpage and the backend sends them the HTML page, how can I incorporate a Java ...

The navigation bar struggles to display list elements without proper line breaks

Recently, I've been immersed in a web development project for a company. For the navigation bar, I opted to use the FlexNav JQuery plugin. While referencing the example on , I encountered an issue when attempting to add more than 5 list elements; they ...

"What's the best way to make sure a checkbox stays checked and its content remains visible after a

After updating my HTML content, it now consists of a hidden table inside a div with the class "myClass": <div class="myClass" style="display:none"> <table class="table table-hover"> ..... </table> </div> The table remains hidden u ...

The unusual behavior of a page refresh in jQuery when replacing content

My website features a flash player. This code references the flash player stored in player_codes.php: <script language="javascript" type="text/javascript" src="songs_related/flashmp3player/swfobject.js" ></script> <!-- Div that contains pl ...

"Implementing jQuery to dynamically set the href attribute for a link when

My website features a tabbed menu that displays content from various WordPress categories including Cars, Trucks, and Buses. The active tab is randomly selected each time the page is reloaded. However, there seems to be an issue with the "View More" button ...

Stacking SVG elements can lead to distortion effects

Currently experimenting with the innovative SVG stacking method to integrate multiple icons into a single file, reducing the browser's HTTP requests. The details of this technique can be found in depth here. In essence, it involves placing numerous S ...

Updating a jQuery div issue

Hey there, I apologize for bothering you again, but I'm facing another issue with jQuery. It's the same code. $('.tab').click(function() { $(this).unbind("click"); var classy = $(this).attr("class").split(" ").splice(- ...

sticky placement changes when option is chosen

I'm experimenting with the CSS style called position: sticky and I've encountered an issue. Everything works perfectly until the select element is activated, causing the page to scroll back to the original position of the sticky element. <div ...

Creating a repeating sequence in HTML: A step-by-step guide

I have an HTML file containing a portfolio. Each portfolio item is structured like this: <div class="item"> <div class="portfolio-item"> <a href="img/portfolio-item-1.jpg" data-lightbox="ima ...

What is the best way to design a div that showcases text on top of a background image, complete with a pointer or arrow, and automatically adjusts its width to properly display the

Is it possible to create a div with an :after selector, containing text that automatically adjusts its width to fit the content? Seems like a complex task, right? It sure can be. I initially tried achieving this using a div id and :after selector, but ra ...

What is the best way to retrieve a table from an HTML page and convert it into a data frame using XML and Rcurl in R programming?

Can someone help me convert a table on the Forbes website into a data.frame? Click here to access the table ...

The conversion of a 2D json array into a string is mistakenly performed

On hand is an outer array that contains 2 arrays within it, making it a 2-dimensional array. This is how the array is initialized: $outerArray = array(); $nestedArray = array("first", "second", "third", "fourth"); $outerArray[] = $nestedArray; $nest ...

Center alignment of text and images within the button's image

Can someone help me format my CSS properly? I have a button image where the text should be on the left side and another image on the right side. Currently, everything is centered. Thank you in advance. Here is the current code: button { /* padding- ...

What is preventing the div container from extending to its full width?

The content on the right side of this div container is struggling to reach full width for some unknown reason. Click here to see an image of the issue. The right column is not extending to full width. This snippet shows my CSS code. The 'main-conte ...

Ways to efficiently update styles dynamically using css and/or javascript

I am trying to update the styles of a button when it is clicked. I initially set the style for the first element on page load, but now I need to remove those styles from the first element and apply them to the clicked button instead. I am having trouble fi ...

Is there a glitch causing the Owl carousel to malfunction?

I am struggling to implement a fullwidth owl carousel slider on my webpage, but I'm facing issues with getting it to function properly. I suspect there might be a conflict with the current template that I'm using. Here is the step-by-step proce ...

Issues with NativeScript WebView displaying HTML file

Having trouble loading a local HTML file into a webview in my NativeScript (typescript) application. Despite using the correct path, it's not loading and instead shows an error. <WebView src="~/assets/content.html" /> An error message stati ...