4

I've been looking for a solution to optimize images for better performance.

After trying some solutions (like sharp and imagemin, which resulted in never smaller, sometimes bigger files), I am now looking to experiment with Google's pagespeed. Unfortunately, pagespeed seems to only support Apache and Nginx, which I would not like to add to my stack just for image optimization (also, I would prefer making the optimization once on upload, and not on server request, even if cached).

I will be very grateful for any information that might help me implement this in native node.js, and for any other (working!) image optimization recommendations.

Noy
  • 1,258
  • 2
  • 11
  • 28

2 Answers2

3

I suggest you only use node for dynamic content (e.g: your application server logic).

For static content, such as images, stylesheets and others... just serve them with a regular web server like nginx. There you can use ngx_pagespeed.

arboreal84
  • 2,086
  • 18
  • 21
1

Try npm module lwip.

It's a standalone library(re-built when installing) and no runtime dependencies.

I use its resize and scale operations to create thumb images in my file service project.

Check if this is what you need. :)

hankchiutw
  • 1,546
  • 1
  • 12
  • 15
  • Interesting, but what about optimization? – Noy Mar 13 '16 at 09:33
  • 1
    Maybe you could combine lwip and imagemin.For example, scale an image with lwip and pipe the out(transfer as a buffer) to imagemin. Check example code in this [gist](https://gist.github.com/hankchiutw/9fb21f2ea14edc2864c6). – hankchiutw Mar 13 '16 at 14:09