performance issues because a lot of image in website - web-performance

I have a lot of images on my website and that makes my website load too slowly. should I create a small image with low quality and small size and make a blur effect on it and make the real images load slowly (lazy load) after all page files are downloaded or what should I do

That's a very interesting issue. I love the answers posted here (very detailed and informative), but - I think that the crux of your problem is the coupling between your page resources and your page load. Thus I think that de-coupling those 2 will make a HUGE difference
The problem
You page is loading with all of it's resources. this results in a slow and leggy page load that reminds us of old-fashion web sites. We want a more modern approach that loads the page in a more elegant way
The Solution
Load your page with light-weight content (such as text)
Present the partially-loaded page to the user with placeholders for the rest of content
in the background - lazy-load heavy page resources (such as images)
let the page populate itself while the user has full access to it
How To Implement
Let's focus on the problem you mentioned - images. You may think they are loading slowly because of their size. But, videos (which are heavier than images) are usually loaded with no problem - because modern video players are loading them in chunks and have a really good strategy to give the user a great experience. So, for now, we will NOT focus on the weight of your resources but instead focus on how to load them properly. It goes without saying (but I'll say it anyway) - AFTER you are getting the results your expected - it is advise to properly handle the size of your images as noted in the other answers
A very simple and effective demo for this:
<style>
img.loader {
display: none;
}
img.loader.active {
display: block;
}
</style>
<script>
function loadImage(target, url) {
const imgElement = target.querySelector('img.target')
const imgLoaderElement = document.createElement('img')
const loaderElement = target.querySelector('img.loader')
imgLoaderElement.onload = event => {
// nice to have - the actual size of the requested image
console.log(imgLoaderElement.width, imgLoaderElement.height)
loaderElement.classList.remove('active')
imgElement.src = url
}
imgLoaderElement.src = url
}
</script>
<div id="image-loader-1">
<img class="active loader" src="https://cdnjs.cloudflare.com/ajax/libs/galleriffic/2.0.1/css/loader.gif" alt="" width="48" height="48">
<img class="target" />
</div>
<button onclick="loadImage(document.querySelector('#image-loader-1'), 'https://picsum.photos/600/400')">
Load Image
</button>
Let's break this down
Your image container is now a div element constructed of 2 elements
a pre-loader - to have a nice effect of loading something
the image element - this will contain the actual image
The function loadImage asks you to specify the target image container (in our example image-loader-1) and the image url (your site or 3rd0party sites - no difference here). It will then create a new image element (without populating it to the dom) and load the image there (while still playing the pre-loader in the background). Only after the image is full loaded (and the url is cached in the browser) - you may attach this url to your real image element (and then - make the pre-loader disappear).
This way, you will always have the benefit to use a loader until the image is ready for view - making your users experience better
Does this looks good? Right now - no, not really. I cleaned all the styling properties from it in order to make this solution as clear as possible.
Can it be better? yes. Just put some styling efforts into it and you are ready
to go
Note: because this is a general question which does not rely on a specific modern framework, I posted a very generic solution using vanilla JS. Hope it is clear enough for future users to understand and implement in their own projects.

There are several things that can be done.
is definitely make the size of images smaller. if they are not taking a lot of website space then it is better to make them smaller because if they are not shown in the resolution the image belongs to you are just wasting a lot of bandwidth and then downscale the image anyway. There are many online image compressor that you can use or you can directly decrease the size from your image viewer most of them have a resize option.
instead of using jpg/jpeg/png use webp. webp is a better format for images since it provides further compression of data and also have a lossless compression 25% better then png. The biggest pro of webp is faster load time and less storage. BUT this might not be supported by all browsers, so before implementing this just check if anyone is still running netscape or not. Last i checked all browser that are used support it.(https://en.wikipedia.org/wiki/WebP#Support)
If you need more optimization there is also a browser addon called lighthouse created by google. just install it, goto your website and click "generate report". It will tell you all the places you can actually optimize your website.
(Chrome- https://developer.chrome.com/docs/lighthouse/overview/
Firefox- https://addons.mozilla.org/en-US/firefox/addon/google-lighthouse/)

Why does it get slow?
Images are too large
Images are not optimized according to the device
Images have unspecified dimensions
You use heavy formats
The browser starts loading images all at once
Your cache doesn’t store images
Solution:
Resize and compress images
Lossy = a filter that eliminates some of the data. The quality of the image is impacted.
Lossless = a filter that compresses the data without touching the quality of the image.
Use
Imagify
Ewww Image Optimizer
Optimole (Image optimization & Lazy Load by Optimole)
ShortPixel Image Optimizer
reSmush.it
Set image dimensions
Serve images optimized for each device
Lazy load your images
Implementing Lazy Loading using a WordPress plugin.
Lazy Loading by WP Rocket is a free plugin that implements the lazy
load script on the images.
Check this interesting guide if you want to compare the best lazy
load plugins available on the market.
Implementing Lazy Loading manually: follow this guide from CodeInWP
that explains the two ways to implement lazy loading manually (not so
easy to follow for beginners, though).
Convert your images to WebP
Credit:https://imagify.io/blog/reasons-images-slow-websites/

just in simple language....
Sites that use too many images, or have images that are too large, have longer loading times. This can slow down your entire page, irritating visitors and actually hurting your site's ranking in online search results.

Related

Is there anyway to increase the load time of a web page due to image quality?

Are there any web tricks to speed up the loading of a web page. I have a few pages where I have images which were created in photoshop, but they are saved as a PNG. The load time is fairly slow of the page due to this, is there anyway to speed up a page load? They are in the region of 1.2/1.5MB
Reducing the size of the file would be a significant advantage.
Additionally converting the asset to webp for Chrome and Firefox, jp2 for Safari and falling back to png would help retain quality while reducing file size.
If the image isn’t in the first viewport you can also try lazy loading the image with something like lazysizes or at the very least the loading attribute.
You could compress the images using an online tool. Although, this may slightly reduce the quality.
I’ve used this site before: https://tinypng.com/
Other than that, I’m not sure if you can “speed up” the load time for a webpage.
You can check your website images here
https://www.imghaste.com/pagespeed/
1.2 to 1.5MB for each image is way large.
You need to adopt a process where you can optimize/shrink images for your website.
If you don't really need the images to be PNG you can always convert them to JPEG.
https://www.imghaste.com/converter

img src with large image size on UIWebView taking time to load and sometimes crashes

I display html string on UIWebview, and html string comes from server.
In html which I retrieved from server, is having 10 images which are large sized with src attribute. those images total size is above 4 MB. when I load this html string into UIWebview, application takes 4 mins to load images sometimes and sometimes it crashes.
I want to know, if there is any solution to <img src..> tag where I can make thumbnail images.
Any response will greatly appreciated.
Thanks
You should be able to find out on the server-side via java/html5 what browser your client is and what features it has. In doing so the server can determine the appropriate image size to send to the client.
My company has successfully implemented this with iPhone and Android client's retrieving images that are smaller in size as opposed to browser's on laptops receiving larger images.
Good luck!
Big chunks of memory allocated can trigger a sigkill 9 from springboard on heavy system load (by protection) even if you don't overlap the 46MB given for any single application running.
The best way to do this would be to load one image at a time.
For each individual image, create a smaller version.
Release the currently big image loaded since you have a smaller version of it.
Do it again for next, and so on.
You will reduce the impact of big loads.
The Nimbus Framework is doing image download and resize that way. Have a look.
For the UIWebview, I'm not sure of what you can do. Since you get the HTML before displaying it, you could perhaps grep the <img> tags and creating those thumbnails, storing them to the iPhone, replacing the src path of the original <img> tags by a local URL of your thumbs.
Probably the device you are using cannot support 4MB images when decompressed in a UIWebView.
Which device are you using?
4 minutes to load 4 images is a very long time. Is your network very bad? Otherwise it could be another indicator of wrong approach.
Being you I'll try to use native UIImageView to display the images and perform some kind of queued download, maybe with ASIHTTP.
So you can load and unload the images when you need them and avid keeping them always in memory.
As Jojas point, I still think that the answer is correct as the UIWevView drains memory to render the DOM elements.

Zoom high quality of the image to full detail without loading a large image on iPhone

I need to develop a feature into an iPhone app which will allow the user to zoom in very much on an image and display high-quality details of the image without loading the large and loading it online. I've found a example here: developer.apple.com/library/ios/#samplecode/ScrollViewSuite/ but it dont seems to zoom at full details,
And the images are store locally.
I have seem apple developer example like PhotoScroller, scrollviewsuite.
but feels they work differently just cutting the image in tiles.
Is it Possible To access asynchronously chunk of data and render it to view at same time in didReceivedData function delegate.
Please provide some tutorial or example.
Thanks
Avinash
Based on what you have said, PhotoScroller is really what you are describing. It is the only example that I know that can handle HUGE images and only display what is needed. I have used it for 100 megapixel images and it works great.

iphone best practice, how to load multiple high quality images

I have about 20-ish high quality images (~3840x5800 px) that I need to load in a simple gallery type app. The user clicks a button and the next image is loaded into the UIImageView.
I currently use [UIImage imageWithContentsOfFile:] which takes about 6 seconds to load each image in the simulator :(
if I use [UIImage imageNamed:] it takes even longer to load but caches the images which means its quicker if the user wishes to see the same images again. But it may cause memory problems later with all that caching crashing my app.
I want to know whats the best practice for loading these? I'm experimenting with reducing image file size as much as is possible but I really need them to be high quality image for the purpose of the app (zoomable, etc.).
Thanks for any advice
[EDIT]
Hey again guys,
Thanks for all ye're advice. The project's spec's have changed a little. Now as well as displaying the images they firstly have to be zoomed in to a particular spot and when the user taps next it zooms out and then displays the next image. So I'm not sure if the proposed solutions fits?
Apple's docs recommend against trying to load single images that are larger than 1024x1024. You should look into using CATiledLayer instead, to load pieces of the images as needed.
You can have a look at this Apple sample:
http://developer.apple.com/library/ios/#samplecode/PhotoScroller/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010080
It shows how to load big images, breaking them in tiles for different zoom levels.
You can't see all those pixels at any given time, so there is no need to load them all. Load lower-res copies ("big-thumbnails") to view the complete image, then selected sub-tiles, maybe of 2 or more different resolution sets, after the user zooms in.
The CATiledLayer API may be able to handle some of the latter for you.

Loading PDFs or Images from URL into a CoverFlow view

I want to load PDFs or Images into a View, but when the source is an URL there might be connection lags, so I wonder what is the best approach when loading content (like magazines) into a Coverflow view in the iPhone?.
(For Coverflow, something like this: http://apparentlogic.com/openflow/ )
Is it ok to get a pdf file then
obtain corresponding page images and
show them in an appropriate
resolution a Coverflow view?
(Downloading the hole PDF might take
long)
Or is better to download images as
needed and then pass them to the
Coverflow? (Although resolution
might be a problem, hence maybe I
wil need more than one image per
page)
Would it be better to have a pdf
file for every page?(So they can be
rendered at any resolution and I
don't have to download the hole file
at once)
I hope you can give some advices on this.
Thanks in advance.
Just for the record:
After some research I came up with images approach. They are the simpler, fastest, and reasonable good resolution. They can be loaded in 2 stages, regular resolution and better resolution for zooming, etc.