<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jansfer - 长风破浪会有时，直挂云帆济沧海 &#187; leverage browser caching</title>
	<atom:link href="http://www.82cs.com/tag/leverage-browser-caching/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.82cs.com</link>
	<description>头顶着“80后”的光环，脚踏实地一步步向前进。</description>
	<lastBuildDate>Wed, 01 Feb 2012 01:31:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>杠杆浏览器缓存，提高网页浏览速度[原创]</title>
		<link>http://www.82cs.com/201002/05/leverage-browser-caching/</link>
		<comments>http://www.82cs.com/201002/05/leverage-browser-caching/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 06:39:33 +0000</pubDate>
		<dc:creator>Jansfer</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[Cache-Control]]></category>
		<category><![CDATA[expiration date]]></category>
		<category><![CDATA[Last-Modified]]></category>
		<category><![CDATA[leverage browser caching]]></category>
		<category><![CDATA[max-age]]></category>
		<category><![CDATA[mod_expires]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.jansfer.com/?p=2403</guid>
		<description><![CDATA[有效的使用浏览器缓存，首先可以提升网页的访问速度，加强用户体验，其次减少页面输出节约服务器带宽。 本文主要讲如何通过apache的mod_expires，或者PHP代码来杠杆（调节）浏览器缓存，即leverage browser caching。 主要参数有：Last-Modified, Cache-Control, max-age, expiration date等。方法很简单 方法一、 设置APACHE，启用mod_expires，并在配置文件中增加以下： ExpiresActive On ExpiresDefault "access plus 12 hours" ExpiresByType text/html "access plus 3 days" ExpiresByType text/plain "access plus 3 days" ExpiresByType text/css "access plus 3 days" ExpiresByType application/javascript "access plus 3 days" ExpiresByType application/x-http-php "access plus 5 minutes" ExpiresByType image/gif "access plus 30 days" ExpiresByType [...]]]></description>
			<content:encoded><![CDATA[<p>有效的使用浏览器缓存，首先可以提升网页的访问速度，加强用户体验，其次减少页面输出节约服务器带宽。</p>
<p>本文主要讲如何通过apache的mod_expires，或者PHP代码来杠杆（调节）浏览器缓存，即leverage browser caching。</p>
<p>主要参数有：Last-Modified, Cache-Control, max-age, expiration date等。方法很简单</p>
<p>方法一、<br />
设置APACHE，启用mod_expires，并在配置文件中增加以下：<br />
<code></p>
<p>ExpiresActive On<br />
ExpiresDefault "access plus 12 hours"<br />
ExpiresByType text/html "access plus 3 days"<br />
ExpiresByType text/plain "access plus 3 days"<br />
ExpiresByType text/css "access plus 3 days"<br />
ExpiresByType application/javascript "access plus 3 days"<br />
ExpiresByType application/x-http-php "access plus 5 minutes"<br />
ExpiresByType image/gif "access plus 30 days"<br />
ExpiresByType image/png "access plus 30 days"<br />
ExpiresByType image/jpeg "access plus 30 days"<br />
ExpiresByType image/x-icon "access plus 30 days"</p>
<p></code><br />
关于mod_expires的启用、各项参数释义请自行<a target="_blank" href="http://www.google.com/search?&#038;q=mod_expires">google</a>，这里不能阐述。<br />
方法二、<br />
适用于不能、不方便配置APACHE的PHP用户，优点是使用简单，缺点仅对PHP页面有效果，对CSS、JS及图片没有效果。<br />
<code><br />
/**<br />
*设置浏览器缓存<br />
*@param int $cachetime<br />
**/<br />
function LeverageBrowserCaching($cachetime = 60) {<br />
if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] != NULL &amp;&amp; ((strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']))+$cachetime) &gt; time()) {<br />
header( "HTTP/1.1 304 Not Modified" );<br />
exit;<br />
}<br />
else {<br />
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");<br />
header("Cache-Control: max-age=" . $cachetime);<br />
}<br />
}<br />
</code><br />
将以上函数放在程序的公用文件当中，在PHP程序的开头调用些文件。注意调用之前不能有任何输出。</p>
<p>END</p>
<h2>Today on history:</h2><ol><li>2009:&nbsp;&nbsp;<a href='http://www.82cs.com/200902/05/install-windows7-by-usb-disk/' title='Permanent Link to 如何通过USB磁盘安装Windows7/Vista'>如何通过USB磁盘安装Windows7/Vista(0)</a></li><li>2008:&nbsp;&nbsp;<a href='http://www.82cs.com/200802/05/archive_627/' title='Permanent Link to 如何设置小灵通的呼叫转移'>如何设置小灵通的呼叫转移(0)</a></li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.82cs.com/201002/05/leverage-browser-caching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

