利用nginx concat模块合并js css
前言:
nginx-http-concat模块是由淘宝网开发的,现在淘宝网合并js和css正是用这个模块,如链接http://a.tbcdn.cn/??s/kissy/1.2.0/kissy-min.js,p/global/1.0/global-min.js,p/fp/2012/core.js,p/fp/2012/fp/module.js,p/fp/2012/fp/util.js,p/fp/2012/fp/directpromo.js?t=2012080620120924.js就是合并了kissy-min.js、global-min.js、core.js、module.js、util.js,directpromo.js等js文件。
环境:
Ubuntu 15.04 64位
步骤:
一、环境准备
安装Nginx之前要先准备好Ubuntu 15的环境,安装好Ubuntu系统之后,还需要安装以下组件:
1、apt-get install openssh-server
Windows用XShell连接,Mac 用自带的Terminal连接
2、sudo apt-get install libssl-dev
3、sudo apt-get install build-essential
编译Nginx和Nginx concat用到
4、sudo apt-get install vim
Linux下强大的编辑器
5、sudo apt-get install git
安装Git用于获取Nginx concat包
6、sudo apt-get install libpcre3 libpcre3-dev
安装Perl库,编译Nginx用到
7、sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
测试Nginx页面
二、安装Nginx
1、下载Nginx
http://nginx.org/download/
mkdir /usr/local/Nginx
cd /usr/local/Nginx
wget http://nginx.org/download/nginx-1.9.9.tar.gz
tar zxvf nginx-1.9..tar.gz
2、下载nginx-http-concat
git clone https://github.com/idefav/nginx-http-concat
mv nginx-http-concat /usr/local/src
三、编译
cd ./nginx-1.9.
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --add-module=/usr/local/src/nginx-http-concat
make && make install
四、配置
打开配置文件
vim /usr/local/nginx/conf/nginx.conf
1、CSS
location /static/css/ {
concat on;
concat_types text/css;
concat_max_files ;
}
2、JS
location /static/js/ {
concat on;
concat_types application/javascript;
concat_max_files 30;
}
3、混合
location /static/all/ {
concat on;
concat_types text/css application/javascript;
concat_max_files ;
concat_unique off;
}
五、启动Nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
六、测试
curl http://localhost/static/??jquery.js,jquery.corner.js
七、开启Gzip
配置Gzip
gzip on;
gzip_min_length 1k;
gzip_buffers 16k;
gzip_disable "MSIE [1-6]\.";
gzip_vary off;
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/javascript;
gzip_comp_level ;
重启Nginx
/usr/local/nginx/sbin/nginx -s reload
测试
/usr/local/nginx# curl -I -H "Accept-Encoding: gzip, deflate" http://192.168.19.128/static/??jquery.js,jquery.corner.js
利用nginx concat模块合并js css的更多相关文章
- 转:利用node压缩、合并js,css,图片
1.安装nodejs http://nodejs.org/ 2.安装各自的node package js我用的是UglifyJS github地址:https://github.com/mishoo/ ...
- Grunt的配置及使用(压缩合并js/css)
Grunt的配置及使用(压缩合并js/css) 安装 前提是你已经安装了nodejs和npm. 你能够在 nodejs.org 下载安装包安装.也能够通过包管理器(比方在 Mac 上用 homebre ...
- Tengine的concat模块与js、css合并
首先,先走出一个误区 ,下面是tengine-cn邮件列表里的一篇邮件原文:“看了这个例子就了解了,这个所谓的合并请求只是把所有的CSS或JAVASCRIPT请求合并,必须是同一个文件类型的.我开始想 ...
- 前端构建工具 Gulp 压缩合并JS/CSS 并添加版本号、ES6转ES5
Gulp 基于 Node.js 的前端构建工具,可以实现前端代码的编译(sass.less).压缩合并(JS.CSS).测试:图片的压缩:已经添加 JS 和 CSS 版本号,防止浏览器缓存. 1. 安 ...
- Web性能优化之动态合并JS/CSS文件并缓存客户端
来源:微信公众号CodeL 在Web开发过程中,会产生很多的js/css文件,传统的引用外部文件的方式会产生多次的http请求,从而加重服务器负担且网页加载缓慢,如何在一次请求中将多个文件一次加载出来 ...
- maven 压缩、合并 js, css
转载自:http://blog.csdn.net/fangxing80/article/details/17639607 我们知道在 Web 应用开发中为了提高客户端响应速度,需要将页面使用的资源最小 ...
- nginx concat模块配置 页面返回400 bad request
在1.4.x版本的nginx没有发现这个问题,但是在1.5.x版本就遇到了这个问题 由于Nginx在新版本中,使用了标准的 MIME-Type:application/javascript.而在ngi ...
- nginx js、css多个请求合并为一个请求(concat模块)
模块介绍 mod_concat模块由淘宝开发,目前已经包含在tengine中,并且淘宝已经在使用这个nginx模块.不过塔暂时没有包含在nginx中.这个模块类似于apache中的modconcat. ...
- 引用:使用grunt 压缩 合并js、css文件
引用:https://www.jianshu.com/p/08c7babdec65 压缩 js 文件 1.创建一个目录 名为grunt 目录.png 2.在grunt目录下创建一个 src目录,存 ...
随机推荐
- BZOJ1119[POI2009]SLO && BZOJ1697[Usaco2007 Feb]Cow Sorting牛排序
Problem J: [POI2009]SLO Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 622 Solved: 302[Submit][Sta ...
- Dev的关于XtraGrid的使用2
接着说,GirdControl如何定位和查找指定列显示值的行(注意是列的实显示值,而不是关联数据源列值) 下面请看代码: using DevExpress.XtraGrid.Views.Base; u ...
- Angular - - $q 承诺与延迟
$q 一个帮助处理异步执行函数的服务.当他们做完处理时,使用它们的返回值(或异常). 受 Kris Kowa’s Q 的启发,这是一个实现promise/deferred对象的启用. $q的两种方式- ...
- JDBC连接SQL Server 2005步骤详解
一.设置SQL Server服务器: 1.“开始” → “程序” → “Microsoft SQL Server 2005” → “配置工具” → “SQL Server Configurati ...
- fork() && fork() || fork()
http://blog.csdn.net/hs794502825/article/details/10242091 #include <unistd.h> #include <std ...
- js如何准确获取当前页面url网址信息
1.window.location.href(设置或获取整个 URL 为字符串) var test = window.location.href;alert(test);返回:http://i.cnb ...
- Blend4 的安装和配置
Microsoft Expression Blend作为一款功能齐全的专业设计工具,可用来针对基于 Microsoft Windows 和基于 Microsoft Silverlight 1.0 的应 ...
- 阿里云服务器windows系统C盘一键清理脚本
@ECHO OFF @echo @echo @echo 清理几个比较多垃圾文件的地方 DEL /F /S /Q "C:\WINDOWS\PCHealth\ERRORREP\QSIGNOFF\ ...
- Java学习之旅基础知识篇:数据类型及流程控制
经过开篇对Java运行机制及相关环境搭建,本篇主要讨论Java程序开发的基础知识点,我简单的梳理一下.在讲解数据类型之前,我顺便提及一下Java注释:单行注释.多行注释以及文档注释,这里重点强调文档注 ...
- JS-鼠标滚轮事件 和 阻止默认行为
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...