<?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; firebug</title>
	<atom:link href="http://dev.juokaz.com/tag/firebug/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>Debugging with FirePHP and Firebug</title>
		<link>http://dev.juokaz.com/php/debugging-with-firephp-and-firebug</link>
		<comments>http://dev.juokaz.com/php/debugging-with-firephp-and-firebug#comments</comments>
		<pubDate>Thu, 12 Mar 2009 15:09:43 +0000</pubDate>
		<dc:creator>Juozas</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Websites]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[execution time]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[firephp]]></category>
		<category><![CDATA[headers]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[profile]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://dev.juokaz.com/?p=355</guid>
		<description><![CDATA[One may debug his application with print(&#8221;) statements all other the place or alert(&#8221;) for JavaScript. Luckily some years ago Firebug extension for Firefox was introduced, which introduced (?) console. Console works absolutely the same as in Linux and can be used not only to execute commands, but receive information from various sources.
To start with, [...]]]></description>
			<content:encoded><![CDATA[<p>One may debug his application with print(&#8221;) statements all other the place or alert(&#8221;) for JavaScript. Luckily some years ago <a href="https://addons.mozilla.org/en-US/firefox/addon/1843">Firebug</a> extension for Firefox was introduced, which introduced (?) console. Console works absolutely the same as in Linux and can be used not only to execute commands, but receive information from various sources.</p>
<p>To start with, I just love <a href="https://addons.mozilla.org/en-US/firefox/addon/6149">FirePHP</a>. This extension extends Firebug itself and allows PHP to show messages in the console.</p>
<p><img class="size-full wp-image-356" style="float: right;" title="FirePHP" src="http://dev.juokaz.com/wp-content/uploads/2009/03/firephp.png" alt="FirePHP" width="402" height="127" />FirePHP use special headers to send required information, so browses without FirePHP doesn&#8217;t feel any difference, but others can easily extract information. It doesn&#8217;t mean that DB profiling information should be visible in production server, but it definitely helps in development stages. If you look at normal website&#8217;s headers you would see something like this:</p>
<pre>HTTP/1.x 200 OK
Date: Thu, 12 Mar 2009 14:29:29 GMT
Server: Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4.1 ...
X-powered-by: PHP/5.2.6-2ubuntu4.1
Content-Length: 0
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html</pre>
<p>where FirePHP modifies it to:</p>
<pre>HTTP/1.x 200 OK
Date: Thu, 12 Mar 2009 14:28:39 GMT
Server: Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4.1 ...
X-powered-by: PHP/5.2.6-2ubuntu4.1
X-Wf-Protocol-1: http://meta.wildfirehq.org/Protocol/JsonStream/0.2
X-Wf-1-Structure-1: http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1
X-Wf-1-Plugin-1: http://meta.firephp.org/Wildfire/Plugin/ZendFramework/FirePHP/1.6.2
X-Wf-1-1-1-1: 56|[{"Type":"INFO","File":"","Line":""},"This is a debug!"]|
X-Wf-1-1-1-2: 58|[{"Type":"ERROR","File":"","Line":""},"This is an error!"]|
Content-Length: 0
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html</pre>
<p><a href="http://www.firephp.org/">FirePHP</a> website has libraries for sending these headers, but since I was trying it when using Zend Framework, I chose Zend_Log_Writer_Firebug module. It works as writer interface for Zend_Log and since Zend_Log is (or should be) used for all logging in ZF, you can get very nice access to all information (execution time, queries, warnings, etc.) from browser. For example, to send something with Zend Framework, code would look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Place this in your bootstrap</span>
<span style="color: #000088;">$writer</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Log_Writer_Firebug<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$logger</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Log<span style="color: #009900;">&#40;</span><span style="color: #000088;">$writer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Use this in your model, view and controller files</span>
<span style="color: #000088;">$logger</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This is a log message!'</span><span style="color: #339933;">,</span> Zend_Log<span style="color: #339933;">::</span><span style="color: #004000;">INFO</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Simple and clean (it won&#8217;t work if Zend_Controller_Front is not used, look at <a href="http://framework.zend.com/manual/en/zend.log.writers.html#zend.log.writers.firebug">manual</a>).</p>
<p>Logging to files still should be used for information which will be required for further analysis, eg. payment gateway errors, but such information as execution time works perfectly in FirePHP. Users doesn&#8217;t care how fast page was rendered, but developers sometimes needs this information and in my opinion, using FirePHP sounds most reasonable. Have you tried it?</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.juokaz.com/php/debugging-with-firephp-and-firebug/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Easy javascript packing with PHP</title>
		<link>http://dev.juokaz.com/php/easy-javascript-packing-with-php</link>
		<comments>http://dev.juokaz.com/php/easy-javascript-packing-with-php#comments</comments>
		<pubDate>Thu, 05 Feb 2009 00:14:00 +0000</pubDate>
		<dc:creator>Juozas</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Websites]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[packed]]></category>
		<category><![CDATA[requests]]></category>
		<category><![CDATA[website speed]]></category>

		<guid isPermaLink="false">http://dev.juokaz.com/?p=24</guid>
		<description><![CDATA[&#8220;JavaScript packing&#8221; is method for reducing JavaScript files size by removing all unnecessary data (obfuscating) and compressing it&#8217;s contents. Most popular is Dean Edward&#8217;s packer, which transforms JavaScripts into something like this:

eval&#40;function&#40;p,a,c,k,e,r&#41;&#123;...

To start with, it&#8217;s very easy to have dynamically packed files (no one wants to pack them by hand, packed versions are only useful [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;JavaScript packing&#8221; is method for reducing JavaScript files size by removing all unnecessary data (<em>obfuscating</em>) and compressing it&#8217;s contents. Most popular is <a href="http://dean.edwards.name/packer/">Dean Edward&#8217;s packer</a>, which transforms JavaScripts into something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>p<span style="color: #339933;">,</span>a<span style="color: #339933;">,</span>c<span style="color: #339933;">,</span>k<span style="color: #339933;">,</span>e<span style="color: #339933;">,</span>r<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>...</pre></div></div>

<p>To start with, it&#8217;s very easy to have dynamically packed files (no one wants to pack them by hand, packed versions are only useful for production, debugging them is harder) with PHP. One of many PHP packers is available on-line at <a href="http://joliclic.free.fr/php/javascript-packer/en/">http://joliclic.free.fr/php/javascript-packer/en/</a>. It&#8217;s simple one-file script which works really well.</p>
<p>JavaScript packing is as simple as:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'class.JavaScriptPacker.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$src</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'my_script.js'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Script file</span>
<span style="color: #000088;">$script</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$packer</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JavaScriptPacker<span style="color: #009900;">&#40;</span><span style="color: #000088;">$script</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Normal'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$packed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$packer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pack</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">header</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: text/javascript; charset=utf-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Length: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$packed</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$packed</span><span style="color: #339933;">;</span></pre></div></div>

<p><em>* Parameters for JavaScriptPacker object can be easily tested in project <a href="http://joliclic.free.fr/php/javascript-packer/en/">website</a>. </em><em>Sometimes packed javascripts don&#8217;t work because of missing &#8220;;&#8221; symbols. I used <a href="http://www.getfirebug.com">FireBug</a> extension for Firefox to find actual problematic lines in unpacked version and correct them. </em></p>
<p>Using this class I created controller for all my JavaScripts, which gets JavaScript name from GET call, checks for cached version and if packed version is not cached &#8211; creates <em>1 day</em> cache and outputs it. Also, I pass JavaScript name in special form: &#8220;filename1-filename2-&#8230; .js&#8221; what let&#8217;s me merge multiple files into one packed version. (<em>it can be optimized even more by storing cached versions as static files and accessing them directly</em>)</p>
<p>Packer alone cannot make a big difference, but by combining it with:</p>
<ul>
<li>multiple files merging</li>
<li>caching (correct headers)</li>
<li>then packing</li>
<li>putting JavaScripts at the bottom of document</li>
</ul>
<p>gives very good results, not only decreasing HTTP calls count, but also time required to render whole website. Still, it&#8217;s very easy to implement whole system since all required libraries (packer, caching, etc.) are available on-line for free.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.juokaz.com/php/easy-javascript-packing-with-php/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
