Mrinmoy Ghoshal
Mrinmoy Ghoshal

Reputation: 2834

How to Decrease Image Loading Time in PHP

I am currently developing a site in PHP where in a page 1000 of images is loading through AJAX. So it is taking a lot of time. Is there any Optimization Technique that can decrease load time. I dont want to change our image quality.

Image encoding will be helpfull?

Upvotes: 4

Views: 1347

Answers (3)

CSᵠ
CSᵠ

Reputation: 10169

Optimization and micro-optimization thoughts:

Decrease Image FileSize

This is probably the most important factor to really decrease the loading time (less to download -> faster to finish)

  • use some image optimization service like SmushIt or some local software like IrfanView
  • find out which is the best format for converting your images
  • try to lose some quality, you'd be surprised to see what 1% does sometimes with little to unpercievable loss
  • strip image MetaData/EXIF if you don't need it

WebServer & Hardware

Access times are another important factor

  • Apache is great but others might perform better for serving image files or small files (eg. Nginx/lightHTTPd)
  • tweak the webserver's config to suit your needs
  • pick a very fast storage (use RAM if possible)

Webpage

  • use a NeverEndingPage/load-on-scroll or "Click for more"
  • paginate your image sets (maybe by importance)
  • make your image containers and links shorter, strip the extension because browsers will get the filetype from the file's header, rename your files as a base(62) counter vs. the regular 1.jpg...20000.jpg (eg. <img src=Q8U>)

Upvotes: 2

Eugene Roeder
Eugene Roeder

Reputation: 219

Look into the caching logic for the pages. The images might be able to be cached by the web server. Do you use Apache or IIS?

Upvotes: 1

Daya
Daya

Reputation: 1170

better to display initially 50 images and load the remaining when page scrolled. here is an example of loading page at the time of scrolling

Upvotes: 0

Related Questions