zoukankan      html  css  js  c++  java
  • Web报文压缩方法

    编译时压缩

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

    这里我列举几个常用的能够用于减少包体大小的插件,我们可以根据项目需求选择性的使用:
    compression-webpack-plugin :该插件能够将资源文件压缩为.gz文件,并且根据客户端的需求按需加载。
    dedupeplugin :抽取出输出包体中的相同或者近似的文件或者代码,可能对于 Entry Chunk 有所负担,不过能有效地减少包体大小。
    uglifyjsplugin :压缩输出块的大小,可以参考官方文档。
    ignoreplugin :用于忽略引入模块中并不需要的内容,譬如当我们引入moment.js时,我们并不需要引入该库中所有的区域设置,因此可以利用该插件忽略不必要的代码。
     

    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 :该插件能够将资源文件压缩为.gz文件,并且根据客户端的需求按需加载。
    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
            })
        ]
    }

    请求中压缩

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

    给express添加压缩中间件

    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')
     
    var app express()
     
    // compress all responses
    app.use(compression())
     
    // add all routes
  • 相关阅读:
    Merge Two Sorted Lists
    Palindrome Number
    Plus One
    Reverse Integer
    Read N Characters Given Read4
    Given two strings S and T, determine if they are both one edit distance apart
    Longest Palindromic Substring
    Missing Ranges
    Java 不被看好前景堪忧?可能是想多了!
    每天数十亿次请求的应用经验分享,值得参考!
  • 原文地址:https://www.cnblogs.com/lightsong/p/12375405.html
Copyright © 2011-2022 走看看