Home >php教程 >PHP开发 >Using the apache module under Windows to merge multiple js and css to improve web page loading speed

Using the apache module under Windows to merge multiple js and css to improve web page loading speed

高洛峰
高洛峰Original
2017-01-04 10:39:311104browse

Today’s websites are becoming more and more expressive, and more and more js and css are loaded on the page. When there are too many js and css on the website page, the browser will open the page very slowly, which significantly reduces the user experience. Using mod_concatx, multiple files can be merged into one http response message, which can effectively improve the loading speed of js/css.

The sample effect is as follows:

Using the apache module under Windows to merge multiple js and css to improve web page loading speed

The mod_concatx module is modified based on mod_concat, thanks for their work.

The original mod_concat module has great reference value, but it has little actual use.

This module has the following three problems:

1. Data will be re-sent to the client every time, and the browser cache is not properly used.
2. There are security vulnerabilities that cause the server to The program is downloaded, such as "/??jquery.js,common.php"
3. When merging each file, there is no gap in between, causing the content to stick together, which may cause errors

Instructions for use:

<link href="/style/??css1.css,css2.css,css3.css" type="text/css" rel="stylesheet"/>
<script src="/js/??js1.js,js2.js,js3.js,js4.js" type="text/javascript"></script>

Module configuration:

Open the apache configuration file httpd.conf

LoadModule concatx_module modules/mod_concatx.dll

Advanced configuration: (The following is the default configuration, you can not configure it)

<IfModule concatx_module>
ConcatxDisable Off
ConcatxCheckModified On
ConcatxSeparator On
ConcatxMaxSize 1024
ConcatxMaxCount 10
ConcatxFileType js,css
</IfModule>

Details Description:

ConcatxDisable On/Off
//是否使用mod_concatx模块
ConcatxCheckModified On/Off
//检查文件是否改动,建议On
ConcatxSeparator On/Off
//合并文件时是否加换行分隔,建议On
ConcatxMaxSize 数字
//合并文件总大小限制最大值,建议不要太大
ConcatxMaxCount 数字
//合并文件总个数限制最大值,建议不要太大
ConcatxFileType js,css
//合并文件类型限制,如不限制填","

Final words:
It is recommended to compile this module yourself, safe and secure

Later improvement direction:
todo: Consider adding js, css compression
todo: Consider Support files parsed by zend
bug: There is a default page loading exception in the directory (consider upper-level hook processing)


More uses the apache module under Windows to merge multiple js , css improves web page loading speed related articles, please pay attention to PHP Chinese website!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn