A
A
Alexey Dugnist2015-12-28 16:20:09
Node.js
Alexey Dugnist, 2015-12-28 16:20:09

Is it possible to compress pictures using compression in express 4...?

Here is the code:

compression 	= require 'compression'
app = module.exports.app = exports.app = express()

app.use(compression())
app.use express.static( path.join(__dirname, '../../public' ) )

showIndexContent = ( req, res ) ->
  # res.setHeader('Content-Type', 'text/event-stream')
  # res.setHeader('Cache-Control', 'no-cache')
  res.sendFile '/', 
    root: path.join(__dirname, '../../public')

app.get '/', showIndexContent

After I start the server -
e4355c1c6cb34e26a85d2ef9132690f6.jpg
I don't see any compression - is it possible to compress pictures...?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Prozorov, 2015-12-29
@Peekab0o

By default, the compression module does not compress pictures. The filter method is responsible for which Content-Type will be compressed (see the documentation) .
By default, the compressible module is used to determine which Content-Type is compressible.
PS There is no practical sense in compressing the same JPEG images. This also applies to other compressed formats such as PNG, GIF. That is why they are absent in the default filter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question