I have been working on a web project with a large amount of images and videos on web site.After hosting it into a server it can be slow down the page to load because of large amount of images.
How can i prevent it?.Is there any way to load image or video after loading my web page with HTML or Javascript ?
2
Answers
There are tons of ways dealing with images and optimize them, the approach below is just one of them:
You can use lazy loading for your images, so images would load only when needed and close to the user’s viewport.
That way, it won’t affect the load & blocking times of your site.
You can do it this way:
Read more about the lazy loading approach at the MDN Docs
Lazy Loading
ex:
Compress Images and maybe use moderns formats WebP;
Maybe try to use different image sizes for different screen sizes using the element or srcset attribute.
Host your images and videos on a CDNs.
For Javascript: Use asynchronous Loading
If you have JavaScript files that are not essential for the initial page load, load them asynchronously.
For essential assets, you can use to instruct the browser to load them early in the page load process.
And maybe you can try to reduce the number of HTTP requests by combining files, using CSS sprites, and reducing the use of external scripts and fonts.