Home > Backend Development > PHP Tutorial > apache mod_expires cache static files

apache mod_expires cache static files

伊谢尔伦
Release: 2016-11-25 15:14:03
Original
1185 people have browsed it

Using static file caching can improve the performance of the server and has the following benefits:

1. Shorten the response time of the service

2. Reduce the load on the server

3. Reduce the usage of network bandwidth

Program correction method

Every time When changing static content (css, js, etc.), change the name as well.

Append version number or Build number.

<link href="/html/std.css?v=2.5.3.text" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="html/std.css?_v=804120090827100441.css" />
Copy after login

The actual css file name on the server side is still std.css, and the version number needs to be added to the html page.

After adding the version number, users can see the modified page every time they update css or js without CTRL+F5 to refresh.

Apache correction method:

Add --enable-expires in the Configure step when installing apache.

After installation, in the modules directory of the apache installation directory, there will be: mod_expires.so

At the same time, it will be automatically added to Httpd.conf

LoadModule expires_module modules/mod_expires.so
Copy after login

httpd.conf configuration

ExpiresActive on
#缓存3天。
ExpiresBytype text/css "access plus 3 days
ExpiresByType application/x-javascript "access plus 3 days "
ExpiresByType image/jpeg "access plus 3 days "
Expiresbytype image/gif "access plus 3 days "
Copy after login


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template