Note that there are some explanatory texts on larger screens.

plurals
  1. POResizing <img> causing slowness
    primarykey
    data
    text
    <p>I am working on a site that will have a lot of images inside of boxes (divs) sorted as a grid (absolute positioning). I have noticed that resizing the images to fit the boxes causes the site to slow down significantly. There are a lot of images (342), but I don't understand why this is the case as the site runs quickly when I don't resize them.</p> <p>Please note: I plan on implementing the dynamic resizing of the boxes in the future. <strong>I mention this to avoid the answer of saving every image at another size. I am interested in knowing the cause of the slowdown not a different method of implementation.</strong></p> <p>The grid is initially made up of boxes (divs) that are 150px * 150px. The grid is in the <code>&lt;body&gt;</code> and initially has no images (just empty divs). When the body has loaded, a JavaScript function places the images into their appropriate box. The JavaScript function relies on PHP for getting the images from a database as well as for resizing. Here are the steps for that section of PHP:</p> <p>1.) PHP gets image filename from database.</p> <p>2.) PHP gets image dimensions (in pixels) and saves them into two variables. I'll call them x and y here.</p> <p>3.) I change x and y so that the image will fit 150px * 150px (or whatever initial value I assign to the boxes' initial dimensions).</p> <p>4.) I use <code>echo</code> to <code>write document.getElementById("PHP given Id").innerHTML = '&lt;img src="PHP given filename" style="width:PHP x value; height:PHP y value"/&gt;';</code>.</p> <p>If I comment out step 3 in my code the site runs quickly (that is commenting out the part that changes x and y from the image default dimensions). I have also tried setting the width and height attributes of the <code>&lt;img&gt;</code> instead of inline CSS but that does not solve the slowness issue.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload