improve-Gzip首屏加载缓慢/刷新后加载缓慢

1.Vue配置compression-webpack-plugin实现Gzip压缩

gzip简介
HTTP协议上的gzip编码是一种用来改进web应用程序性能的技术,web服务器和客户端(浏览器)必须共同支持gzip。目前主流的浏览器,Chrome,firefox,IE等都支持该协议。

简单来说,gzip是一种压缩技术。经过gzip压缩后页面大小可以变为原来的30%甚至更小,这样,用户浏览页面的时候速度会快得多。

客户端和服务器之间是如何通信来支持gzip

2.安装引入安装compression-webpack-plugin

npm i compression-webpack-plugin@5.0.1 -D // 5.0.1版本合适

对应的依赖包

3. vue.config.js 配置插件compression-webpack-plugin

// 引用插件
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const productionGzipExtensions = ['html', 'js', 'css']
vueConfig.configureWebpack.plugins.push(
    new CompressionWebpackPlugin({
      filename: '[path].gz[query]',
      algorithm: 'gzip',
      test: new RegExp(
      '\\.(' + productionGzipExtensions.join('|') + ')$'
    ),
    threshold: 10240, // 只有大小大于该值的资源会被处理 10240
    minRatio: 0.8, // 只有压缩率小于这个值的资源才会被处理
    deleteOriginalAssets: false // 删除原文件
  }))

 4.npm run build 打包查看是否成功 ,文件后缀.gz

5.nginx 启用 gzip

http {
server {
location / {
# 启用 gzip
gzip on;
# gzip_static是nginx对于静态文件的处理模块,该模块可以读取预先压缩的gz文件,这样可以减少每次请求进行gzip压缩的CPU资源消耗。
gzip_static on;
# 低于 1KB 的文件不压缩,建议设置,否则低于 1KB 的文件可能会反向压缩
gzip_min_length 1k;
# 设置 gzip 版本 P.S.:通常设置为 1.1 版本,但是针对微前端中的子应用,1.1 版本过高,可能导致 gzip 启用不成功,建议设置为 1.0
gzip_http_version 1.0;
# gzip 压缩级别,1 - 10,数字越大,压缩越好,也越占 CPU ,鉴于设置中间数
gzip_comp_level 6;
# 配置禁用 gzip 条件,支持正则,此处表示低于 IE6 版本不启用
gzip_disable "msie6";
# 设置压缩所需要的缓冲区大小
# 获取多少内存用于缓存压缩结果,4 16k表示以16k*4为单位获得,默认 4 8k
gzip_buffers 4 8k;
# nginx做为反向代理时启用
# off(关闭所有代理结果的数据的压缩),
# expired(启用压缩,如果header头中包括"Expires"头信息),
# no-cache(启用压缩,header头中包含"Cache-Control:no-cache"),
# no-store(启用压缩,header头中包含"Cache-Control:no-store"),
# private(启用压缩,header头中包含"Cache-Control:private"),
# no_last_modefied(启用压缩,header头中不包含"Last-Modified"),
# no_etag(启用压缩,如果header头中不包含"Etag"头信息),
# auth(启用压缩,如果header头中包含"Authorization"头信息)
gzip_proxied any;
# 启用应答头"Vary: Accept-Encoding"
gzip_vary on;
# 设置需要压缩的MIME类型,非设置值不进行压缩,其中text/html被系统强制启用
# P.S.:设置文件类型时,如下几个类型建议设置:application/javascript application/x-javascript text/css ,如果设置不匹配,同样 gzip 未启用
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
}
}
}

  • 13
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 设计sigma-delta转换器是一个复杂的过程,需要经过多个步骤。以下是在MATLAB / Simulink中设计sigma-delta转换器的一般过程: 1. 确定系统规格:首先,确定sigma-delta转换器的采样率、精度要求和输入输出范围等系统规格。 2. 模型建立:使用Simulink建立sigma-delta转换器的模型。该模型包括一个Σ(summing)节点、一个Δ(differential)节点和一个比较器节点。使用研究成果相关的数学模型,可以更准确地描述转换器的行为。 3. 参数选择:选择适当的参数来满足系统规格。包括选择合适的阶数和过采样率。过采样率越高,转换器的性能越好,但同时也会增加计算的复杂性和系统复杂度。 4. 仿真验证:使用Simulink对模型进行仿真验证。这可以帮助我们了解系统的性能如何受到不同参数选取的影响。 5. 优化调整:根据仿真结果,对转换器的参数和结构进行优化调整。例如,可以调整Σ节点和Δ节点之间的连接方式,或者优化误差补偿电路的设计。 6. 输出结果:根据优化后的模型,输出设计好的sigma-delta转换器的结果。这可以包括模型中各个节点和参数的数值值。 此外,在设计sigma-delta转换器的过程中,还需要考虑一些其他的因素,如抗噪声能力、计算要求、电路复杂度和成本等。根据具体的需求和约束条件,可以对上述过程进行调整和扩展,以获得最佳的设计结果。 总而言之,设计sigma-delta转换器需要经历模型建立、参数选择、仿真验证、优化调整和输出结果等多个步骤。通过这些步骤,可以获得一个满足系统要求的优化转换器设计。 ### 回答2: Sigma-delta (ΣΔ) converters are commonly used in analog-to-digital (ADC) and digital-to-analog (DAC) applications. They are known for their outstanding performance in terms of resolution, noise shaping, and dynamic range. To design a Sigma-delta converter in MATLAB/Simulink, we can follow the following steps: 1. Specify the converter's specifications: Determine the required resolution, sampling frequency, and input signal bandwidth to meet the desired performance requirements. 2. Model the Sigma-delta modulator: Create a Simulink model to represent the Sigma-delta modulator. This can be done by using Simulink blocks such as Adders, Delays, and Comparators. 3. Define the Analog-to-Digital Converter (ADC): Add the ADC block to the Simulink model and configure its parameters, such as the number of bits, input range, and sampling frequency. 4. Implement the digital decimation filter: Insert a digital decimation filter after the ADC block to remove out-of-band noise and further improve the overall performance. The decimation filter can be modeled using filter blocks in Simulink. 5. Evaluate the performance: Simulate the Simulink model with different input signals and study the system's response. Analyze the output waveform, signal-to-noise ratio (SNR), and other performance metrics to assess the design's effectiveness. 6. Optimize the design: Based on the performance analysis, make design adjustments to enhance the overall system's performance. This can involve modifying filter parameters, changing the modulator architecture, or adjusting the decimation filter design. 7. Verify the design: Validate the design by testing it with various input signals and comparing the simulation results with the desired specifications. 8. Implement the design: Once the design is finalized, the Sigma-delta converter can be implemented in hardware using appropriate components. In summary, to design a Sigma-delta converter in MATLAB/Simulink, we start by specifying the converter's specifications, modeling the modulator and ADC in Simulink, adding a digital decimation filter, evaluating the performance, optimizing the design, verifying the design, and finally implementing it in hardware.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值