专业编程基础技术教程

网站首页 > 基础教程 正文

http请求中小文件合并怎么做?Nginx模块concat有妙招

ccvgpt 2024-07-23 01:17:01 基础教程 17 ℃

今天我们来介绍一个阿里巴巴提供的模块Caoncat。

它到底有什么用呢?

http请求中小文件合并怎么做?Nginx模块concat有妙招

这个模块可以在一次http请求中返回多个文件的内容。

对于我们在web系统中,提升小文件请求的性能是十分有帮助的。



下面我们来介绍一下Concat模块的用法:

功能:上面介绍了,就是当页面需要访问多个小文件时,把他们的内容合并到一次http响应中返回,提升性能。

这并不是一个官方模块,它的github地址:

https://github.com/alibaba/nginx-http-concat.git

安装步骤:

1.先从github上 clone到本地。

2. 在编译Nginx的时候 加上 --add-module=../nginx-http-concat/ (这里的目录是你自己clone的地址)就能编译进Nginx了。这时候Nginx才具有concat的功能。


使用方式:

1.在URL后加上??,放多个文件,这些文件是通过,来分隔的。

2.如果还有参数,则在最后通过?添加参数。

如:

https://g.alicdn.com/??universal/polyfill/0.0.2/p/index/index.js,mtb/lib-env/1.9.9/env.js,mtb/lib-mtop/2.5.1/mtop.js


相关指令:

// 启用开关
concat: on | off
default: concat off
Context: http, server, location

// 对哪些文件进行合并
concat_types: MIME types
Default: concat_types: text/css application/x-javascript
Context: http, server, location

// 是否对多种类型进行合并
concat_unique: on | off
Default: concat_unique on
Context: http, server, location

// 最多合并多少个文件,默认是10个文件
concat_max_files: numberp
Default: concat_max_files 10
Context: http, server, location

// 多个文件的分隔符
concat_delimiter: string
Default: NONE
Context: http, server, locatione

// 多个文件中 某个文件出现错误是否忽略继续返回其他正常的文件
concat_ignore_file_error: on | off
Default: off
Context: http, server, location

Tags:

最近发表
标签列表