user3226932
user3226932

Reputation: 2232

How to compress images with clientside Javascript fetched from the server?

I'm retrieving images from an API server in Javascript but want to compress them (since they are rather big files that are slowing down my website's load time) to display. How can I compress these images using Javascript, or what tools are out there that are good for this to speed up my website's overall performance?

Upvotes: 0

Views: 243

Answers (2)

Ankit Agarwal
Ankit Agarwal

Reputation: 1348

Solution to your problem is enabling gzip compression in your server from which you are getting images. It will drastically improve the network load time of your application

Upvotes: 1

Jake Sylvestre
Jake Sylvestre

Reputation: 945

Unfortunately compressing them on the client side isn't going to shrink your pages size, and will slow load time down. In order to shrink these images you will have to shrink them in whatever your server side language is. The problem with compressing on the client side is the client still has to download the image to compress it and the client has to compress it slowing down their load time even more.

What you want to do, if possible is api--->server--->minify--->send to client.

If you don't have a server to do this with, or your page is static I'd recommend implementing caching , or minifying your javascript.

Upvotes: 1

Related Questions