Question

nginx: compressing images of a Node.js website

Hi, 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.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.