Image optimization, recomendations

November 9, 2016 722 views
API MySQL Node.js Ubuntu

I have an app loading a fair amount of images like facebook. Larger png files take a bit longer to show up and download. I'm on the $10 a month plan running an nginx reverse proxy with Node and MySQL.

Would something like s3 be better for image speed or do I just need to upgrade digital ocean and/or optimize things?

Any recommendations would be greatly appreciated.

Thanks.

Keith

2 Answers
xMudrii November 9, 2016
Accepted Answer

You need to do optimization of server. You don't need to upgrade anything on DigitalOcean. You already have SSD storage, which is fastest available.

For static images or images you upload to site manually, compress it. There are many services that can do it for you. I can recommend TinyPNG. I think it's great service for compressing PNGs and JPGs, in my case, results was great.

Little tinkering on server can help. Setup caching correctly, it can help a lot, as it stores content in clients Browser. How to Implement Browser Caching with Nginx's header Module on Ubuntu 16.04.

You need to find a way to compress image before uploading, if end user is uploading, and you can't use some service like TinyPNG to compress image, you need to find way to do it client/server side.
There is GZIP compression, but if you go over How To Add the gzip Module to Nginx on Ubuntu 14.04 you'll see that GZIP is not giving so much results. You can give it a try and see if it'll go well for you, but I don't think so.
Maybe something like J-I-C ~ Javascript Image Compressor (github.com) can help, but I never used it and don't know is it working on giving results.

You can think about setting up some CDN solution so you can delivery content to users faster. There are many services that can do that for you, free and paid. Usually I recommend CloudFlare, as it's probably most popular and wide used service for CDN and much more.

You need to try and see does something of these help you. I hope you'll make it work better. ;)

How fast a website will load depends on the size of all of the files that have to be downloaded by the browser. Reducing the size of files to be transmitted can make the website not only load faster, but also cheaper to those who have to pay for their bandwidth usage. In this guide, we'll discuss how to configure Nginx installed on your Ubuntu 14.04 server to utilize `gzip` compression to reduce the size of content sent to website visitors.
  • Thank you for the very detailed reply, that will definitely help me out a lot as I didn't know much about this area. I'll first give TinyPNG a shot and see if I can get that working correctly with node.

    Thanks.

    Keith

    • @xMudrii great pointers! Especially when you're on production servers/domains with little to no development going on there.

      I'd also recommend to be careful around caching on development servers/domains. You want changes on those servers to reflect immediately on the browser...caching will slow down that.

as @xMudrii replied, caching with nginx header module and cloudflare should do the trick.

also if your app create multiple version of images for different devices, nginx has recently released Image‑Filter module for that. that might give you some extra benefit.

https://www.nginx.com/blog/responsive-images-without-headaches-nginx-plus/

Have another answer? Share your knowledge.