Let the browser cache css, JS, pictures, static files and so on is very important things, so as to reduce the pressure on the server, the provincial browser often go to the service side to download these static files. Let's look at the configuration method below.
1. Open the Apache extension mod_expires.so and include the following line of code in the Apache configuration file.
LoadModule Expires_module modules/mod_expires.so
2. Configure the cache to include the following snippet in the Apache configuration file
<ifmodule expires_module>
#打开缓存
Expiresactive on
#css文件缓存7200000/3600/24=83 Days
Expiresbytype Text/css A7200000
#js文件缓存7200000/3600/24=83 Days
Expiresbytype Application/x-javascript A7200000
Expiresbytype Application/javascript A7200000
#html文件缓存7200000/3600/24=83 Days
Expiresbytype text/html A7200000
#图片文件缓存7200000/3600/24=83 Days
Expiresbytype Image/jpeg A7200000
Expiresbytype Image/gif A7200000
Expiresbytype Image/png A7200000
Expiresbytype Image/x-icon A7200000
</IfModule>
3. Testing
Access to files with pictures, css,js,html
Http://localhost:8080/test/test.html
With Firebug you can see that the response header information contains
Expires |
Tue, 13 Sep 2011 15:41:09GMT |
Cache-control |
max-age=7200000 |
How to put not configure the cache, the above header information is not, haha, try it.
Apache uses Expires_module to let the browser cache static files