nginx 开启gzip 优化element admin 运行速度

 安装compression-webpack-plugin插件

npm install --save-dev compression-webpack-plugin

安装后进行vue.config.js配置

在 chainWebpack 节点下添加以下配置

  if (process.env.NODE_ENV === 'production') {
      const CompressionWebpackPlugin = require('compression-webpack-plugin')
      const productionGzipExtensions = ['html','js', 'css']

      return {
        plugins: [
          new CompressionWebpackPlugin({
            filename: '[path].gz[query]',
            algorithm: 'gzip',
            test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
            threshold: 10240, // 只有大小大于该值的资源会被处理 10240
            minRatio: 0.8, // 只有压缩率小于这个值的资源才会被处理
            deleteOriginalAssets: false // 删除原文件true=删
          })
        ]
      }
    }
在nginx添加完整配置
server {
	listen  80;
	server_name  xx.xx.com;
	gzip on;
        gzip_min_length 1k;
        gzip_comp_level 9;
        gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
        gzip_vary on;
        gzip_disable "MSIE [1-6]\.";


	location / {
	    # 指定文件的根目录,主要结尾不要带/
	    root /www/xx/web/dist;
	    # 指定默认跳转页面尾 /index.html
	    index index.html;
	    # 防止刷新后404
	    try_files $uri $uri/ /index.html;
        }
    }

修改配置后重启即可 经测试 原来5秒多现在一秒左右

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值