nginx: compressing images of a Node.js website

September 16, 2016 371 views
MEAN Nginx Ubuntu

I've recently rebuilt a former WP site with Node.js using MongoDB and Express.
Now I'm struggling to adhere to PageSpeed Insights. Despite the fact that I'm using a proxy, nginx's gzip compression works well by simply enabling it in my {server} block. Images, on the other hand, are cached by Express using .static() but now Google asks me to compress images. I've googled a lot and also ran an exhaustive search on npm but it doesn't seem to be an answer out there. Where should I work? nginx? Express? Both?

Thanks in advance.

1 Answer

Are you generating images in your code or just displaying static ones? If it's the later you can likely handle this in your pipeline rather than in your code itself. This guide from google has more information on what PageSpeed looks for in optimized images. For example, on our blog we manually optimize images prior to pushing them to our Git repository using a service like tinypng. This required no changes to codebase but simply another step in our assets pipeline.

Have another answer? Share your knowledge.