JavaScript Render Many Images in Single Page

I'm investigating a performance issue we are having with a web form and figured I would do well to solicit some opinions here on this.

This page, on load on the server side, retrieves a list of ID values that are then used to seed a javascript block that is added at the end of the load event. The javascript then loops through these IDs and adds an img element for each such ID, using the ID to set the src attribute.

Previously, this worked fine due to a limitation of only ever showing the first 20 such images found. The business now wants to remove this limitation, which means we could reasonably see hundreds of such images and when testing this, the page takes an unacceptably long time to render all of these img elements.

Simplified pseudo-code for the JS:

for (var i = 0; i < ids.length; i++) {
     var img = "<img src='some\path\'" + ids[i];
     //add img to document
}

Personally, I'd suggest we just keep the limitation in place for now as we are very late in the dev cycle for this release, but I'd like to see what, if anything, we could do to speed this up. All options are on the table, we just need all of images to be displayed. Are there alternative strategies out there to handle this sort of scenario?

Please let me know if any other details would be beneficial.
EDIT
I neglected to mention the reason that all of these images need to be loaded is that this page is used for printing all of these images, so paging won't really work. I agree on this not being a great design choice, but the users and/or business owners want a print-friendly page that shows all of these images. The "normal" page for this same functionality does use paging and performs admirably.
EDIT 2
Now that I am back at the office I can provide a little more detail:

  • The img elements are using an aspx page as their src, the actual image contents are retrieved from a database in that other page and streamed back as a response using a content type of image/png, so that's a further slow down, but given the current architecture, it is necessary as we only store these images in the database
  • These images can vary in size, but a couple MB for a single image would not be unusual

These responses are confirming what I thought: this is not a good idea

Answer:1

To create a fast loading page with multiple images(hundreds) to print, you can't use png's at a big resolution.

First of all convert all images to jpg(keep the originals) in a size which should just big enough to print.

150dpi should be enough.

That means if you put 2 images side by side on a 20cm width paper 500pixel is enough for the max width.

so around 5-15kb per image

if you print on photopaper 1200pixels.(but that taakes longer to load 30-40kb per image)


then in most browsers you can use inches or cm's to create a nice impagination.


if you want to print those images on one page you can use a packing script to calculate the the max size for each image.

like this

var best_square3=function(w,h,n){
 var s=Math.sqrt(w*h/n),c=Math.floor(w/s),r=Math.floor(h/s),t=c*r;
 while(t<=n){
  s--;
  c=Math.floor(w/s);
  r=Math.floor(h/s);
  t=c*r;
 }
 return [w,h,n,s,c,r,c*r,Math.floor(s),((100/w)*(w/c))+'%',((100/h)*(h/r))+'%'];
}

demo .... click somewhere inside the result box

http://jsfiddle.net/e7My4/1/

in that case your images can be much smaller. so 100px*100px max.


i personally use php and fpdf to create pdf's to download/print everythime i update the images/db

EDIT

As your using aspx (which i don't use since various years) you need to find a aspx script to resize the images before you output them in a smaller format(like i told you above) in jpg as you don't need transparency.

Answer:2

Do not display them all at once. Nobody could reasonably work with 100s of images at once. Use some kind of paging mechanism that would display, say, 10 images at a time.

It could be your own paging or one of the dozen jQuery image sliders/rotators/galleries.

Answer:3

I tried to get a value from a file with .config extension using the below code, but i am not able to get it........... if i change the file extesion from .config to .xml the its working fine(I am ...

I tried to get a value from a file with .config extension using the below code, but i am not able to get it........... if i change the file extesion from .config to .xml the its working fine(I am ...

  1. read value from dictionary c#
  2. read value from json
  3. read value from appsettings.json
  4. read value from app.config c#
  5. read value from properties file in java
  6. read value from file bash
  7. read value from cell vba
  8. read value from json string in java
  9. read value from dictionary python
  10. read value from web.config c#
  11. read value from file c++
  12. read value from appsettings.json .net core
  13. read value from file python
  14. read value from datatable c#
  15. read value from jobject c#
  16. read value from dataframe
  17. read value from console in java
  18. read value from json file java
  19. read value from application.properties
  20. read value from console in c#

I am writting a firefox os application and I found a strange problem. I have two web activities (open a link on a projects tab and sending an e-mail on the users tab ) what are work correctly under ...

I am writting a firefox os application and I found a strange problem. I have two web activities (open a link on a projects tab and sending an e-mail on the users tab ) what are work correctly under ...

I want to build a JavaScript regular expression to match all words starting with "ad" or "ae", or all words that contain "-ad" and "-ae". This is what I've tried: var regex_string = "^[ad|ae]|-[ad|...

I want to build a JavaScript regular expression to match all words starting with "ad" or "ae", or all words that contain "-ad" and "-ae". This is what I've tried: var regex_string = "^[ad|ae]|-[ad|...

  1. regular expressions javascript cheat sheet
  2. regular expressions javascript tutorial
  3. regular expressions javascript examples
  4. regular expressions javascript
  5. regular expressions javascript online
  6. regular expressions javascript w3schools
  7. regular expressions javascript mdn
  8. regular expressions javascript pdf
  9. regular expressions javascript test
  10. regular expressions js
  11. regular expression javascript tester
  12. regular expression javascript email
  13. regular expression javascript validation
  14. regular expression javascript match
  15. regular expression javascript replace
  16. regular expression javascript generator
  17. regular expression javascript only numbers
  18. regular expression javascript special characters
  19. regular expression javascript phone number
  20. regular expression javascript email validation

I have an controller which is simply watching a 'name' property and prints its new and old values on any change. function Ctrl($scope) { $scope.$watch('name', function(newValue, oldValue) { ...

I have an controller which is simply watching a 'name' property and prints its new and old values on any change. function Ctrl($scope) { $scope.$watch('name', function(newValue, oldValue) { ...