编译时压缩

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

最新文章

  1. The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder is not applicable for the arguments
  2. Duilib实现QQ聊天窗口晃动
  3. ZOJ 3903 Ant(数学,推公示+乘法逆元)
  4. window.location.href问题,点击,跳转到首页
  5. Gstreamer的一些基本概念与A/V同步分析
  6. iOS调用系统声音与振动
  7. 何为分类,UIImageView举例
  8. Visual Studio 2012 开发环境配置+控制台工具+桌面应用程序
  9. iOS initWithFrame、initWithCoder、awakeFromNib的区别解析
  10. 树莓派Raspberry实践笔记-简单方法安装minicom
  11. 限制容器对CPU的使用 - 每天5分钟玩转 Docker 容器技术(28)
  12. mysql数据库表卡死解决方法
  13. Element UI toggleRowExpansion用法
  14. innodb 关键特性(insert buffer)
  15. CF1083E The Fair Nut and Rectangles
  16. (转)同一服务器部署多个tomcat时的端口号修改详情
  17. kindle书摘-围城-相爱勿相伤
  18. Qt——文件对话框
  19. LncRNA
  20. matlab pca基础知识

热门文章

  1. VUE - 取消默认事件
  2. Linux动静态库
  3. ionic实现滑动的三种方式
  4. 使用Spring Data JPA的Spring Boot
  5. hashCode() 和 equals()的问题解答及重写示范
  6. 008、MySQL日期时间格式化输出
  7. 创建一个TCP代理
  8. 吴裕雄--天生自然java开发常用类库学习笔记:Iterator接口
  9. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-forward
  10. flask邮箱注册问题