You should know that you only need to set max-age or expires. The following method is used to set apache:
Generate to enable
The code is as follows: |
Copy code |
LoadModule headers_module modules/mod_headers.so |
Then write it under the. htaccess file
The code is as follows: |
Copy code |
<IfModule mod_headers.c> <FilesMatch "\. (ico | pdf | flv | jpg | jpeg | png | gif | js | css | swf) $"> Header set Cache-Control "max-age = 604800, public" </FilesMatch> <FilesMatch "\. (xml | txt) $"> Header set Cache-Control "max-age = 18000, public, must-revalidate" </FilesMatch> <FilesMatch "\. (html | htm | php | shtml) $"> Header set Cache-Control "max-age = 3600, must-revalidate" </FilesMatch> </IfModule> |
If the "mod_headers" module is not enabled and the "<IfModule mod_headers.c>" condition is not added, an error will occur on the website!
Setting max-age or expires is used to cache static files and speed up website loading!