<?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>Juozas devBlog &#187; yslow</title>
	<atom:link href="http://dev.juokaz.com/tag/yslow/feed" rel="self" type="application/rss+xml" />
	<link>http://dev.juokaz.com</link>
	<description>Random ideas, scripts and facts</description>
	<lastBuildDate>Mon, 22 Mar 2010 10:48:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Correct headers for dynamically generated content</title>
		<link>http://dev.juokaz.com/php/correct-headers-for-dynamically-generated-content</link>
		<comments>http://dev.juokaz.com/php/correct-headers-for-dynamically-generated-content#comments</comments>
		<pubDate>Sun, 15 Feb 2009 19:00:39 +0000</pubDate>
		<dc:creator>Juozas</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Websites]]></category>
		<category><![CDATA[headers]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[load time]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[uahoo]]></category>
		<category><![CDATA[yahoo]]></category>
		<category><![CDATA[yslow]]></category>

		<guid isPermaLink="false">http://dev.juokaz.com/?p=155</guid>
		<description><![CDATA[Static images have correct headers &#8211; Apache sends them by default. Different story is with all dynamic generating content &#8211; if you don&#8217;t send correct headers user&#8217;s browser will load it every time. It&#8217;s not always good, because generated thumbnails doesn&#8217;t change every time and should be cached in browser&#8217;s cache. If you want to [...]]]></description>
			<content:encoded><![CDATA[<p>Static images have correct headers &#8211; Apache sends them by default. Different story is with all dynamic generating content &#8211; if you don&#8217;t send correct headers user&#8217;s browser will load it every time. It&#8217;s not always good, because generated thumbnails doesn&#8217;t change every time and should be cached in browser&#8217;s cache. If you want to reduce server load and increase loading speed you definitely need to send correct headers.</p>
<p>Our task is to give browser enough information to identify content, which later can be used to decided if content has changed, and if not &#8211; say it to browser without sending content again. Bigger picture is explained <a href="http://thoughtpad.net/alan-dean/http-headers-status.jpg">here</a>, I really recommend analysing it a little bit &#8211; it gives better understanding how headers work and what they mean.</p>
<p>As you saw in <a href="http://thoughtpad.net/alan-dean/http-headers-status.jpg">headers map</a>, there are many possible headers to send, but we can focus on three of them:</p>
<ol>
<li>Etag. Unique identified for output data (maybe hash)</li>
<li>Last-Modified. Date of last data modification</li>
<li>Expires. When to expire content</li>
</ol>
<p>Constructing algorithm is pretty simple, it can be explained in pseudo-code:</p>
<pre>get request headers
   is content expired
      send content, new headers
   else is content different (Etag)
      send content, new headers
   else
      304 header, no content</pre>
<p>I&#8217;ve created <em>outputCacheHeaders(&#8230;)</em> function which (available <a href="http://dev.juokaz.com/examples/expires-etag/headers.phps">here</a>) outputs all required headers and returns true if you need to output content or false if not. All you need to do is pass modification time, live time and data (two last ones are not required). Live time says how long should cache be kept and data is used to generate Etag. Very simple!</p>
<p>After enabling correct headers sending, my websites started to feel much faster, because HTTP requests takes much less time. Also, <a href="http://developer.yahoo.com/performance/rules.html">Yahoo performance tips</a> are really worth reading, really. There are many great tips and I have been using many of them for a long time. These tricks are much much more significant than 0.1 s. faster PHP rendering time.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.juokaz.com/php/correct-headers-for-dynamically-generated-content/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
