<?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>Quinterox &#187; set expire</title>
	<atom:link href="http://www.quinterox.com/content/tag/set-expire/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.quinterox.com/content</link>
	<description>Cesar Quinteros</description>
	<lastBuildDate>Sun, 20 Jun 2010 04:51:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Adding expire tags to your CSS and JavaScript files</title>
		<link>http://www.quinterox.com/content/blog/expire-tags-adding-them-to-your-css-javascript/</link>
		<comments>http://www.quinterox.com/content/blog/expire-tags-adding-them-to-your-css-javascript/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 08:02:33 +0000</pubDate>
		<dc:creator>Cesar Quinteros</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[set expire]]></category>

		<guid isPermaLink="false">http://www.quinterox.com/content/?p=451</guid>
		<description><![CDATA[Adding expiration headers to PHP/ASP files.]]></description>
			<content:encoded><![CDATA[<p>Though we live in an age where a lot of people have fast internet connections. The focus (at least for developers) has shifted to technologies that relieve the server of heavy workloads and increase processing speeds such as AJAX, using server-side and client-side caching, as well as gzipping. In this post I will lightly touch upon client-side caching of dynamically generated CSS and JavaScript files.</p>
<p>I recently installed YSlow, a handy web development tool for Firefox. In it there is an option that tells you whether your CSS or JavaScript files are cached on the client&#8217;s computer allowing for a quicker page load. I noticed my files were not cached so I looked a little into how to go about caching them so the browser won&#8217;t download the same file over and over when going from page to page. So I went about conducting my own tests to see how to make this happen. The only way of making it happen other than setting an expire date/time on the WHOLE page (or on the .htaccess file in Linux servers) was to create a server-side file that would output the expiration, content type headers as well as the actual styles/code in your web application. Below is a clearer picture of how I made it happen.</p>
<h3>PHP- Step 1.</h3>
<p>Make a dynamically generated CSS file that includes expiration and content headers (code below). Save it as &#8216;dynamic_css.php&#8217;. The actual CSS styling can be typed in the same way you would do in a regular stylesheet, we are only after getting those expiration and content type headers sent out.</p>
<pre>&lt;?php
header("Expires: Thu, 31 Dec 2020 20:00:00 GMT");
header('Content-type: text/css');
?&gt;
h1 { color: Red; }</pre>
<p><br class="clear" /></p>
<h3>PHP- Step 2.</h3>
<p>Add &#8216;dynamic_css.php&#8217; as the CSS href of you document. This should make YSlow happy and increase the speed at which the user navigates through pages that use the same CSS file. Use the same method to add expiration tags to JavaScript.</p>
<pre>&lt;link rel="stylesheet" type="text/css" <strong><span style="color: #ff0000;">href="dynamic_css.php"</span></strong>/&gt;</pre>
<p><br class="clear" /></p>
<h3>ASP- Step 1.</h3>
<p>The way I added expire tags to my CSS code in ASP is very similar to PHP&#8217;s. First you make a server-side CSS file and save it as &#8216;dynamic_css.aspx&#8217;. Since it is important the headers hit the server first we use server-side code  to send those out first. We type in the actual CSS code like we would in a regular CSS file after that. Besides would you really want to Response.Write() all of your CSS code? I think not.</p>
<pre>&lt;%
    Response.Expires = 3600
    Response.ContentType = "text/css"
%&gt;
    h1 { color: Blue; }</pre>
<p><br class="clear" /></p>
<h3>ASP- Step 2.</h3>
<p>Add &#8216;dynamic_css.aspx&#8217; as the CSS source of you document. This should make YSlow happy since the expiration headers are now being sent increasing the speed at which the user navigates through the pages that share the same CSS file. Use this same header method to add expiration tags to JavaScript files.</p>
<pre>&lt;link rel="stylesheet" type="text/css" <strong><span style="color: #ff0000;">href="dynamic_css.aspx"</span></strong>/&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.quinterox.com/content/blog/expire-tags-adding-them-to-your-css-javascript/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
