<?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>Michael Hartmayer - Portfolio &#187; HTTP</title>
	<atom:link href="http://www.michaelhartmayer.com/tag/http/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.michaelhartmayer.com</link>
	<description>Have a Leet Smoothy</description>
	<lastBuildDate>Wed, 21 Jul 2010 04:04:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>PHP LoadScript Class</title>
		<link>http://www.michaelhartmayer.com/php/php-loadscript-class/</link>
		<comments>http://www.michaelhartmayer.com/php/php-loadscript-class/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 03:46:16 +0000</pubDate>
		<dc:creator>Michael Hartmayer</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Optimization]]></category>

		<guid isPermaLink="false">http://www.michaelhartmayer.com/?p=289</guid>
		<description><![CDATA[This is a really handy class I wrote that loads all your scripts Server Side so that when your page loads there aren&#8217;t so many HTTP Requests. Useful if you&#8217;re trying to load 6 different js files and 4 different style sheets, or whatever. That&#8217;s 10 requests, completely gone. Just keep in mind that it [...]]]></description>
			<content:encoded><![CDATA[<p>This is a really handy class I wrote that loads all your scripts Server Side so that when your page loads there aren&#8217;t so many HTTP Requests. Useful if you&#8217;re trying to load 6 different js files and 4 different style sheets, or whatever. That&#8217;s 10 requests, completely gone. Just keep in mind that it dumps all your files straight into the html document- so, as long as you don&#8217;t have a problem with that, this is a great tool.</p>
<p>In addition, it&#8217;s really easy to add your own script types. Check out the script for details.</p>
<p>( Available At: <a title="PasteBin: LoadScript Class" rel="nofollow" href="http://pastebin.com/f5241789e" target="_blank">PasteBin: LoadScript Class</a> )</p>
<p>Usage:</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: #666666; font-style: italic;"># Include Class
</span>   <span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'class.scriptloader.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;"># Instantiate
</span>   <span style="color: #000088;">$jsLoader</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ScriptLoader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'JS'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;"># Add Scripts
</span>   <span style="color: #000088;">$jsLoader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addScript</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my-javascript.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$jsLoader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addScript</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$jsLoader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addScript</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'other-scripts.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;"># Dump into Document
</span>   <span style="color: #000088;">$jsLoader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">echoScripts</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>On a quick note, it&#8217;d probably be a lot &#8216;neater&#8217; to mod-rewrite a php file to handle at least one request per script type. That way it doesn&#8217;t all get dumped straight into the page.</p>
<p>Something like:</p>
<p><em>RewriteRule ^script\.(.*)$ script-loader.php?type=$1 [L]</em></p>
<p>And for <strong>script-loader.php</strong></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: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'js'</span><span style="color: #339933;">:</span>
         <span style="color: #666666; font-style: italic;">// Load all of the JavaScript files here</span>
         <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>That way when you load something like <strong>script.js</strong> it will dump all of your java scripts into a &#8216;fake&#8217; file. Just make sure to use the default <em>$<span style="text-decoration: underline;">ScriptLoader</span>-&gt;type</em> (don&#8217;t set one when instantiating) if you are loading it from a <em>src=&#8221;foo.bar&#8221;</em>.</p>
<p>.. or something like that xD</p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Share and Enjoy:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fphp-loadscript-class%2F&amp;title=PHP%20LoadScript%20Class&amp;bodytext=This%20is%20a%20really%20handy%20class%20I%20wrote%20that%20loads%20all%20your%20scripts%20Server%20Side%20so%20that%20when%20your%20page%20loads%20there%20aren%27t%20so%20many%20HTTP%20Requests.%20Useful%20if%20you%27re%20trying%20to%20load%206%20different%20js%20files%20and%204%20different%20style%20sheets%2C%20or%20whatever.%20That%27s%2010%20re" title="Digg"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://sphinn.com/index.php?c=post&amp;m=submit&amp;link=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fphp-loadscript-class%2F" title="Sphinn"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fphp-loadscript-class%2F&amp;title=PHP%20LoadScript%20Class&amp;notes=This%20is%20a%20really%20handy%20class%20I%20wrote%20that%20loads%20all%20your%20scripts%20Server%20Side%20so%20that%20when%20your%20page%20loads%20there%20aren%27t%20so%20many%20HTTP%20Requests.%20Useful%20if%20you%27re%20trying%20to%20load%206%20different%20js%20files%20and%204%20different%20style%20sheets%2C%20or%20whatever.%20That%27s%2010%20re" title="del.icio.us"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fphp-loadscript-class%2F&amp;t=PHP%20LoadScript%20Class" title="Facebook"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fphp-loadscript-class%2F&amp;title=PHP%20LoadScript%20Class" title="Mixx"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fphp-loadscript-class%2F&amp;title=PHP%20LoadScript%20Class&amp;annotation=This%20is%20a%20really%20handy%20class%20I%20wrote%20that%20loads%20all%20your%20scripts%20Server%20Side%20so%20that%20when%20your%20page%20loads%20there%20aren%27t%20so%20many%20HTTP%20Requests.%20Useful%20if%20you%27re%20trying%20to%20load%206%20different%20js%20files%20and%204%20different%20style%20sheets%2C%20or%20whatever.%20That%27s%2010%20re" title="Google Bookmarks"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fphp-loadscript-class%2F&amp;title=PHP%20LoadScript%20Class&amp;source=Michael+Hartmayer+-+Portfolio+Have+a+Leet+Smoothy&amp;summary=This%20is%20a%20really%20handy%20class%20I%20wrote%20that%20loads%20all%20your%20scripts%20Server%20Side%20so%20that%20when%20your%20page%20loads%20there%20aren%27t%20so%20many%20HTTP%20Requests.%20Useful%20if%20you%27re%20trying%20to%20load%206%20different%20js%20files%20and%204%20different%20style%20sheets%2C%20or%20whatever.%20That%27s%2010%20re" title="LinkedIn"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fphp-loadscript-class%2F&amp;title=PHP%20LoadScript%20Class" title="Live"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fphp-loadscript-class%2F&amp;t=PHP%20LoadScript%20Class" title="MySpace"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fphp-loadscript-class%2F&amp;title=PHP%20LoadScript%20Class" title="Reddit"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.michaelhartmayer.com%2Fphp%2Fphp-loadscript-class%2F&amp;title=PHP%20LoadScript%20Class" title="StumbleUpon"><img src="http://www.michaelhartmayer.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.michaelhartmayer.com/php/php-loadscript-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
