Web message compression method

Compile-time compression

https://www.cnblogs.com/qiuzhimutou/p/7592875.html

Here I have listed a few common packet can be used to reduce the size of the plug body, we can use selective according to the needs of the project:
compression-webpack-plugin: This plugin can be resource files are compressed as .gz file and loaded on demand according to the needs of the client.
dedupeplugin: extracting the same or similar code output file or the package body, may be subject to the burden Entry Chunk, but can effectively reduce the size of the package body.
uglifyjsplugin: size of the compressed output blocks, refer to the official documentation.
ignoreplugin: module for ignoring the content does not require the introduction of, for example, when we introduce moment.js, we do not need to introduce all the regions in the library is provided, so that the plug can be used to ignore unnecessary code.
 

https://www.webpackjs.com/plugins/uglifyjs-webpack-plugin/

[
  new UglifyJsPlugin({ uglifyOptions: { ie8: false, ecma: 8, parse: {...options}, mangle: { ...options, properties: { // mangle property options } }, output: { comments: false, beautify: false, ...options }, compress: {...options}, warnings: false } }) ]


-----
new webpack.optimize.UglifyJsPlugin({
mangle: true,
compress: {
warnings: false, // Suppress uglification warnings
pure_getters: true,
unsafe: true,
unsafe_comps: true,
screw_ie8: true
},
output: {
comments: false,
},
exclude: [/\.min\.js$/gi] // skip pre-minified libs
}),

https://www.webpackjs.com/plugins/compression-webpack-plugin/

compression-webpack-plugin: This plugin can be resource files are compressed as .gz file and loaded on demand according to the needs of the client.
var CompressionPlugin = require("compression-webpack-plugin");
module.exports = {
    plugins: [
        new CompressionPlugin({
            asset: "[path].gz[query]",
            algorithm: "gzip",
            test: /\.(js|html)$/,
            threshold: 10240,
            minRatio: 0.8
        })
    ]
}

 

 

Compression request

https://www.npmjs.com/package/compression

Add compression to express middleware

Node.js compression middleware.

The following compression codings are supported:

  • deflate
  • gzip

The middleware will attempt to compress response bodies for all request that traverse through the middleware, based on the given options.

 

When using this module with express or connect, simply app.use the module as high as you like. Requests that pass through the middleware will be compressed.

var compression require('compression')
var express require('express')
 
was app  Out ( )
 
// compress all responses
app.use(compression())
 
// add all routes

 

Guess you like

Origin www.cnblogs.com/lightsong/p/12375405.html