Answers:
更新您的Apache配置,以将以下指令作为核心配置的一部分:
#
# associate .js with "text/javascript" type (if not present in mime.conf)
#
AddType text/javascript .js
#
# configure mod_expires
#
# URL: http://httpd.apache.org/docs/2.2/mod/mod_expires.html
#
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType image/x-icon "access plus 2692000 seconds"
ExpiresByType image/jpeg "access plus 2692000 seconds"
ExpiresByType image/png "access plus 2692000 seconds"
ExpiresByType image/gif "access plus 2692000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2692000 seconds"
ExpiresByType text/css "access plus 2692000 seconds"
ExpiresByType text/javascript "access plus 2692000 seconds"
ExpiresByType application/x-javascript "access plus 2692000 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
</IfModule>
#
# configure mod_headers
#
# URL: http://httpd.apache.org/docs/2.2/mod/mod_headers.html
#
<IfModule mod_headers.c>
<FilesMatch "\\.(ico|jpe?g|png|gif|swf|css|js)$">
Header set Cache-Control "max-age=2692000, public"
</FilesMatch>
<FilesMatch "\\.(x?html?|php)$">
Header set Cache-Control "max-age=600, private, must-revalidate"
</FilesMatch>
Header unset ETag
Header unset Last-Modified
</IfModule>
这取决于主机和服务器处理这些事情的方式。选项1)如果您控制服务器,则使apache在响应中添加到期标头选项2)如果您不控制Web服务器,或者您对images / js / css / etc进行服务器管理,则可以从脚本中设置这些标头服务器他们
请记住,这些提示是可取的,但不是绝对的真理。它们不仅可以节省带宽,还可以加快网站访问速度。因此,如果您的网站访问量很少,则不必为此担心太多。
在Lightspeed Web Server中设置过期
登录到管理控制台,然后>服务器->常规->过期设置->按类型过期
添加以下内容:
text/css=A604800, text/javascript=A604800, application/javascript=A604800, application/x-javascript=A604800, application/x-shockwave-flash=A604800, image/gif=A604800, image/jpg=A604800, image/jpeg=A604800, image/png=A604800, image/ico=A604800, image/icon=A604800
604800是到期的秒数,它应为您的需要,因为它的168小时为7天。另外,Light Speed Server确实使用htaccess,您需要添加以下行:
ExpiresActive On
或者,如果您没有管理控制台访问权限,请尝试以下.htaccess文件:
ExpiresByType image/png A604800
ExpiresByType image/gif A604800
ExpiresByType image/jpg A604800
ExpiresByType image/jpeg A604800
ExpiresByType text/javascript A604800
ExpiresByType application/x-javascript A604800
ExpiresByType text/css A604800