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