<?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>LAMPlights &#187; cdn</title>
	<atom:link href="http://www.hermanradtke.com/blog/tag/cdn/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hermanradtke.com</link>
	<description>Personal anecdotes from my experiences using the LAMP stack</description>
	<lastBuildDate>Wed, 25 Jan 2012 18:14:47 +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>Scaling URL&#8217;s</title>
		<link>http://www.hermanradtke.com/blog/scaling-urls/</link>
		<comments>http://www.hermanradtke.com/blog/scaling-urls/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 22:22:33 +0000</pubDate>
		<dc:creator>Herman Radtke</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cdn]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[scaling]]></category>
		<category><![CDATA[url]]></category>

		<guid isPermaLink="false">http://www.hermanradtke.com/blog/?p=211</guid>
		<description><![CDATA[Using non-relative URL's during early development can alleviate a lot of growing pains. This may seem counter-intuitive at first, but hear me out. We all learned long ago to stop hard-coding the domain name into the href attribute of an anchor tag. Instead, we used relative URL's such as '/index.php' to make our code much [...]]]></description>
			<content:encoded><![CDATA[<p>Using non-relative URL's during early development can alleviate a lot of growing pains.  This may seem counter-intuitive at first, but hear me out.  We all learned long ago to stop hard-coding the domain name into the href attribute of an anchor tag.  Instead, we used relative URL's such as '/index.php' to make our code much more portable.  However, relative URL's become a pain point when trying to scale your website.  Let's review some common scenarios that can be averted with some proper planning.</p>
<p><span id="more-211"></span></p>
<p>Common scenario's:</p>
<ol>
<li>The time comes for a CDN and all images need to be served up with a URL like cdn.example.com.</li>
<li>The use of SSL is very common for authentication and other sensitive user information.  The problem is that SSL is much slower than a normal http request.  Traffic needs to be segregated by changing the SSL URL's from https://www.example.com to https://secure.example.com.</li>
</ol>
<p>The solution to these problems is quite trivial: simply prepend a domain to a relative URL.  Consider the following config file:</p>
<pre>
[development]
site.cdn = "http://dev.example.com"
site.ssl = "https://dev.example.com"

[production]
site.cdn = "http://cdn.example.com"
site.ssl = "https://secure.example.com"
</pre>
<p>This configuration uses special URL values for a production environment, but uses the standard development server URL so the developers can still develop.  A simple addition to the php bootstrap file can set up defines to use in html templates.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'CDN'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">site</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cdn</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SSL'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">site</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ssl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And then in a .phtml file you can simply do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;img src=&quot;&lt;?=CDN&gt;/images/hero.png&quot;&gt;
&nbsp;
&lt;a href=&quot;&lt;?=SSL&gt;/login.php&quot;&gt;Login&lt;/a&gt;</pre></div></div>

<p>Consider prepending the domain for all URL's in your application, not just those types listed above.  There are plenty of scenario's that may require AJAX calls or even normal GET/POST request to use different domains.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hermanradtke.com/blog/scaling-urls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

