webpack打包gz文件,nginx开启gzip压缩

wepback配置

webpack4配合"compression-webpack-plugin": "^6.1.2"打包压缩gz

typescript 复制代码
chain.plugin("compression").use(
        new CompressionPlugin({
          test: /\.js$|\.html$|\.css$/,
          threshold: 10240, // 超过10KB的压缩
          deleteOriginalAssets: false,// 保留源文件
        })
      )

上传文件到服务器

nginx配置

typescript 复制代码
location /h5/ {
		gzip on;	// 动态压缩,如果没有gz文件再压缩
		gzip_static on;// 优先返回静态gz文件
		gzip_http_version 1.1;
		gzip_proxied expired no-cache no-store private auth;
		gzip_vary on;
		gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
        add_header Cache-Control no-store;
        index  index.html;
        }
相关推荐
东方小月7 小时前
从零开发一个 Coding Agent(四):使用状态机校验大模型事件流
前端·人工智能·后端
Csvn7 小时前
🧩 ESM vs CJS 混用的 7 个「天坑」——从 TypeScript 编译到 Node 与浏览器
前端
Csvn7 小时前
🎯 Web 性能 API 集合:Performance Observer 的 5 个冷门妙用
前端
Csvn8 小时前
深入 React 闭包陷阱:从根源上理解并根治 stale closure
前端
whyfail8 小时前
前端学 Spring Boot(8):接口为什么越用越慢?
前端·spring boot·后端
用户059540174468 小时前
LangChain 记忆测试踩坑实录:这两个坑让我排查了 4 小时
前端·css
程序员黑豆8 小时前
鸿蒙应用开发:@Monitor 装饰器使用教程
前端·harmonyos
SamChan909 小时前
在Web应用中集成PDF多语言翻译功能:PDFTranslator API实战指南
前端·python·ai·pdf·yapi·机器翻译
kyriewen9 小时前
AI Agent 9秒删光了生产数据库——我给自己的项目做了5个紧急检查
前端·ai编程·claude
IT_陈寒10 小时前
JavaScript的this又双叒叕让我怀疑人生了
前端·人工智能·后端