<?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>The html blog &#187; html</title>
	<atom:link href="http://htmlblog.net/tag/html/feed/" rel="self" type="application/rss+xml" />
	<link>http://htmlblog.net</link>
	<description>The web sandbox of Asvin Balloo</description>
	<lastBuildDate>Wed, 07 Oct 2009 17:20:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>8 practical tips to make your web pages faster</title>
		<link>http://htmlblog.net/8-practical-tips-to-make-your-web-pages-faster/</link>
		<comments>http://htmlblog.net/8-practical-tips-to-make-your-web-pages-faster/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 16:36:23 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[best practices]]></category>
		<category><![CDATA[fast]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[mod_deflate]]></category>
		<category><![CDATA[mod_expires]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[speed up]]></category>
		<category><![CDATA[yahoo]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=40</guid>
		<description><![CDATA[

Yahoo's Exceptional Performance team has compiled a list of 34 best practices to have faster web pages. In this post I'll show you 8 tips which helped me to get a B grade in YSlow! for web pages that I develop. Currently YSlow's web page analysis is based on 13 identified basic rules that affect [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://farm4.static.flickr.com/3062/2520059957_ae331ae75a.jpg?v=0" alt="" /></p>
<div style="clear:both"></div>
<p><a href="http://developer.yahoo.com/performance/rules.html" target="_blank">Yahoo's Exceptional Performance team</a> has compiled a list of <a href="http://developer.yahoo.com/performance/rules.html" target="_blank">34 best practices</a> to have faster web pages. In this post I'll show you 8 tips which helped me to get a B grade in <a href="http://developer.yahoo.com/yslow/" target="_blank">YSlow!</a> for web pages that I develop. Currently YSlow's web page analysis is based on 13 identified basic rules that affect web page performance. In decreasing order of priority they are:</p>
<ol>
<li><a href="http://developer.yahoo.com/performance/rules.html#num_http" target="_blank">Make Fewer HTTP Requests</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#cdn" target="_blank">Use a Content Delivery Network</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#expires" target="_blank">Add an Expires Header</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#gzip" target="_blank">Gzip Components</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#css_top" target="_blank">Put CSS at the Top</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#js_bottom" target="_blank">Move Scripts to the Bottom</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#css_expressions" target="_blank">Avoid CSS Expressions</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#external" target="_blank">Make JavaScript and CSS External</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#dns_lookups" target="_blank">Reduce DNS Lookups</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#minify" target="_blank">Minify JavaScript</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#redirects" target="_blank">Avoid Redirects</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#js_dupes" target="_blank">Remove Duplicate Scripts</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#etags" target="_blank">Configure ETags</a></li>
</ol>
<p>You can get more info by clicking on each item. Of course using a <a href="http://en.wikipedia.org/wiki/Content_Delivery_Network" target="_blank">CDN</a> is not affordable by everybody, including me. This didn't prevent me to have a B grade though. I will guide you through some of the items which worked for me.<br />
<span id="more-40"></span></p>
<hr/>
<strong>Make Fewer HTTP Requests</strong><br />
If you're using the <a href="http://developer.yahoo.com" target="_blank">YUI library</a>, the good news is that recently the team graciously offered a <a href="http://developer.yahoo.com/yui/articles/hosting/" target="_blank">Combo Handler Service</a>, served from their CDN. This helps us to eliminate HTTP requests by requesting a single file. For example, to use the <a href="http://developer.yahoo.com/yui/editor/" target="_blank">Rich Text editor</a>, it needed 6 separate HTTP requests:</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/2.5.2/build/yahoo-dom-event/yahoo-dom-event.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/2.5.2/build/container/container_core-min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/2.5.2/build/menu/menu-min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/2.5.2/build/element/element-beta-min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/2.5.2/build/button/button-min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/2.5.2/build/editor/editor-beta-min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
&nbsp;</pre>
<p>Now with the Combo Handler service, it has been stripped to only 1 file:</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/combo?2.5.2/build/yahoo-dom-event/yahoo-dom-event.js&amp;2.5.2/build/container/container_core-min.js&amp;2.5.2/build/menu/menu-min.js&amp;2.5.2/build/element/element-beta-min.js&amp;2.5.2/build/button/button-min.js&amp;2.5.2/build/editor/editor-beta-min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
&nbsp;</pre>
<p>If you're not using the YUI library or not interested in using the Combo Handler service, you can try <a href="http://code.google.com/p/minify/" target="_blank">Minify!</a><br />
<a href="http://code.google.com/p/minify/" target="_blank">Minify</a> is a <a href="http://php.net" target="_blank">PHP5</a> app that can combine multiple CSS or Javascript files, compress their contents (i.e. removal of unnecessary whitespace/comments), and serve the results with HTTP encoding (gzip/deflate) and headers that allow optimal client-side caching.</p>
<p>Another tool which can be helpful is <a href="http://shrinksafe.dojotoolkit.org/" target="_blank">Dojo Shrinksafe</a> which not only minifies your javascript code but also allows you to upload several javascript files and have them compressed in 1 single file.</p>
<p>Another way to make fewer HTTP requests is by using CSS sprites which are big images containing lots of smaller ones. An online tool which can make CSS sprites out of your smaller ones is the <a href="http://spritegen.website-performance.org/" target="_blank">CSS Sprite Generator</a>. You just have to upload your pics and it will generate your sprite together with the CSS code. More info about CSS sprites can be found on <a href="http://css-tricks.com/css-sprites-what-they-are-why-theyre-cool-and-how-to-use-them/" target="_blank">CSS Tricks</a>.</p>
<hr/>
<strong>Add an Expires Header</strong><br />
For this to work on Apache, you'll need to have <a href="http://httpd.apache.org/docs/2.0/mod/mod_expires.html" target="_blank">mod_expires</a> enabled. Then create an .htaccess file or edit your httpd.conf with the following content:</p>
<pre class="apache">&nbsp;
<span style="color: #00007f;">ExpiresActive</span> <span style="color: #0000ff;">On</span>
<span style="color: #00007f;">ExpiresByType</span> image/jpg <span style="color: #7f007f;">&quot;access plus 2 years&quot;</span>
<span style="color: #00007f;">ExpiresByType</span> image/jpeg <span style="color: #7f007f;">&quot;access plus 2 years&quot;</span>
<span style="color: #00007f;">ExpiresByType</span> image/gif <span style="color: #7f007f;">&quot;access plus 2 years&quot;</span>
<span style="color: #00007f;">ExpiresByType</span> application/javascript <span style="color: #7f007f;">&quot;access plus 2 years&quot;</span>
<span style="color: #00007f;">ExpiresByTYpe</span> text/css <span style="color: #7f007f;">&quot;access plus 2 years&quot;</span>
&nbsp;</pre>
<p>In the above listing, all images(jpg/jpeg/gif) will have an expires header 2 years in the future.</p>
<hr/>
<strong>Gzip Components</strong><br />
You must have <a href="http://httpd.apache.org/docs/2.0/mod/mod_deflate.html" target="_blank">mod_deflate</a> enabled and drop these lines in your httpd.conf file</p>
<pre class="apache">&nbsp;
SetOutputFilter DEFLATE
<span style="color: #00007f;">SetEnvIfNoCase</span> Request_URI \.<span style="color: #66cc66;">&#40;</span>?:gif|jpe?g|png<span style="color: #66cc66;">&#41;</span>$ no-gzip dont-vary
<span style="color: #00007f;">SetEnvIfNoCase</span> Request_URI \.<span style="color: #66cc66;">&#40;</span>?:exe|t?gz|zip|bz2|sit|rar<span style="color: #66cc66;">&#41;</span>$ no-gzip dont-vary
<span style="color: #00007f;">SetEnvIfNoCase</span> Request_URI \.pdf$ no-gzip dont-vary
&nbsp;</pre>
<hr/>
<strong>Put CSS at the Top</strong><br />
All CSS must be between your head tag, like that :</p>
<pre class="html4strict">&nbsp;
	<span style="color: #009900;"><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">&lt;html&gt;</span></a></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">&lt;head&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/link.html"><span style="color: #000000; font-weight: bold;">&lt;link</span></a> <span style="color: #000066;">rel</span>=<span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;style.css&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span>=<span style="color: #ff0000;">&quot;screen&quot;</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head&gt;</span></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">&lt;body&gt;</span></a></span>
&nbsp;
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html&gt;</span></span>
&nbsp;</pre>
<hr/>
<strong>Move Scripts to the Bottom</strong><br />
While the CSS are sitting at the top of your page, javascripts must be moved towards the lower part of your page, typically in the body tag. I usually put them before the closing body tag.</p>
<pre class="html4strict">&nbsp;
	<span style="color: #009900;"><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">&lt;html&gt;</span></a></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">&lt;head&gt;</span></a></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head&gt;</span></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">&lt;body&gt;</span></a></span>
		...
		...
		<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;myjs.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html&gt;</span></span>
&nbsp;</pre>
<hr/>
<strong>Reduce DNS Lookups</strong><br />
I don't usually have more than 2 DNS lookups in my scripts, else YSlow will be removing some points.</p>
<hr/>
<strong>Minify JavaScript</strong><br />
As I mentioned earlier on, <a href="http://shrinksafe.dojotoolkit.org/" target="_blank">Dojo Shrinksafe</a> is an online tool which minifies your code.</p>
<p>Another great command line tool is <a href="http://www.julienlecomte.net/blog/2007/08/11/" target="_blank">Julien Lecomte YUI Compressor</a>. </p>
<p>In order to use it you must have <a href="http://java.sun.com" target="_blank">Java</a> installed (>= 1.4).</p>
<p><a href="http://www.crockford.com/" target="_blank">Douglas Crockford</a> also has something similar in <a href="http://www.crockford.com/javascript/jsmin.html" target="_blank">JSMin</a></p>
<hr/>
<strong>Configure ETags</strong><br />
Just drop this line in your httpd.conf:</p>
<pre class="apache">&nbsp;
FileETag <span style="color: #0000ff;">None</span>
&nbsp;</pre>
<p>;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/8-practical-tips-to-make-your-web-pages-faster/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Show/hide containers by only adding CSS classes without writing javascript code (YUI-based)</title>
		<link>http://htmlblog.net/showhide-containers-by-only-adding-css-classes-without-writing-javascript-code-yui-based/</link>
		<comments>http://htmlblog.net/showhide-containers-by-only-adding-css-classes-without-writing-javascript-code-yui-based/#comments</comments>
		<pubDate>Sat, 20 Sep 2008 07:37:49 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[collapse]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[expand]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[selector]]></category>
		<category><![CDATA[yahoo]]></category>
		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=34</guid>
		<description><![CDATA[

This post will show you how to add the collapse/expand functionality in your HTML pages, perfect for FAQs by only adding two class names to your existing page and including the scripts below. Of course it's all YUI-based and also a demo of the fantastic YUI selector utility.
Demo of the toggler
Download the javascript file

What does [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://farm1.static.flickr.com/50/156713983_c264885895.jpg?v=0" alt="html code" /></p>
<div style="clear:both"></div>
<p>This post will show you how to add the collapse/expand functionality in your HTML pages, perfect for FAQs by only adding two class names to your existing page and including the scripts below. Of course it's all YUI-based and also a demo of the fantastic <a href="http://developer.yahoo.com/yui/selector/">YUI selector utility</a>.</p>
<p><a href="http://htmlblog.net/demo/toggler/" target="_blank"><strong>Demo of the toggler</strong></a><br />
<a href="http://htmlblog.net/demo/toggler/toggler.zip"><strong>Download the javascript file</strong></a><br />
<span id="more-34"></span><br />
<strong>What does the script do ?</strong><br />
OK, suppose you have a FAQ page where you have traditional anchor methods, i.e you click on the question and then you go to the bottom of the page to get the answer or you get redirected to another page. But now your users are complaining your site's not trendy enough and want to have the answer displayed immediately after clicking the question.</p>
<p><strong>The solution.</strong><br />
After downloading the javascript file, include it at the bottom of your page with the following HTML code:</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/combo?2.5.2/build/yahoo-dom-event/yahoo-dom-event.js&amp;2.5.2/build/selector/selector-beta-min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;js/toggler.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
&nbsp;</pre>
<p>We need to include the <a href="http://developer.yahoo.com/yui/selector/">selector utility</a> which will be used to retrieve a collection of elements that match a given CSS selector. For e.g if we want to retrieve all div nodes in HTML page having the class "foo", we can write :</p>
<pre class="javascript">&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> myNodes = YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Selector</span>.<span style="color: #006600;">query</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'div.foo'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>The selector is used in the toggler.js file.</p>
<p>After adding the scripts, now you have to add CSS classes to your containers. For example for the FAQ, for questions (or main, call it whatever you want), you add the class "htmlblog-main" and for the answers (or sub), add the "htmlblog-sub" class.</p>
<p>Before :</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div&gt;</span></a></span>1. Question<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div&gt;</span></a></span>Answer1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div&gt;</span></a></span>2. Question 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div&gt;</span></a></span>Answer 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
&nbsp;</pre>
<p>After :</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;htmlblog-main&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>1. Question<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;htmlblog-sub&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Answer1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;htmlblog-main&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>2. Question 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;htmlblog-sub&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Answer 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
&nbsp;</pre>
<p>If you already had a class for that container, no problem you can add the htmlblog-main or htmlblog-sub class :</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;myclass htmlblog-main&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>1. Question<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
&nbsp;</pre>
<p><strong>What next ? </strong><br />
That's all ! All your answer containers will be hidden and questions will have a [+] besides them. Pretty easy</p>
<p><strong>Am I obliged to use the htmlblog-main and html-sub classes ? And I don't want to use div tags, I want li tags.</strong><br />
Don't worry, if you don't like the class names you can put whatever you want but you'll have to edit the toggler.js file at the following lines :</p>
<pre class="javascript">&nbsp;
YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Event</span>.<span style="color: #006600;">addListener</span><span style="color: #66cc66;">&#40;</span>window, <span style="color: #3366CC;">'load'</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	YAHOO.<span style="color: #006600;">htmlblog</span>.<span style="color: #006600;">init</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'div'</span>, <span style="color: #3366CC;">'htmlblog-main'</span>, <span style="color: #3366CC;">'htmlblog-sub'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>For e.g, if you're using li tags instead of divs with the "myMainClass" as main and "mySubClass" as sub, the code goes :</p>
<pre class="javascript">&nbsp;
YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Event</span>.<span style="color: #006600;">addListener</span><span style="color: #66cc66;">&#40;</span>window, <span style="color: #3366CC;">'load'</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	YAHOO.<span style="color: #006600;">htmlblog</span>.<span style="color: #006600;">init</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'li'</span>, <span style="color: #3366CC;">'myMainClass'</span>, <span style="color: #3366CC;">'mySubClass'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p><strong>I'am getting an alert saying "Number of main and subs incorrect".</strong><br />
That means the number of main/subs are not the same. You need to have the number of the main class equals the number of the sub class.</p>
<p>I've commented the toggler.js file and you can easily change it to fit your needs.</p>
<p><a href="http://htmlblog.net/demo/toggler/" target="_blank"><strong>Demo of the toggler</strong></a><br />
<a href="http://htmlblog.net/demo/toggler/toggler.zip"><strong>Download the javascript file</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/showhide-containers-by-only-adding-css-classes-without-writing-javascript-code-yui-based/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SEO friendly URL in PHP</title>
		<link>http://htmlblog.net/seo-friendly-url-in-php/</link>
		<comments>http://htmlblog.net/seo-friendly-url-in-php/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 18:10:51 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[clean url]]></category>
		<category><![CDATA[french characters]]></category>
		<category><![CDATA[friendly]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[modifier]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[smarty]]></category>
		<category><![CDATA[template engine]]></category>
		<category><![CDATA[url]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=24</guid>
		<description><![CDATA[

When I started implementing mod_rewrite in websites I had a problem in PHP as how to make a SEO friendly URL. All tutorials were geared towards how to implement mod_rewrite, about modifying .htaccess files, but none treated how to make the urls friendly with dynamic content. For example I have a news section which are [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://farm1.static.flickr.com/253/516400565_132600bf8a_o.gif" alt="SEO friendly" /></p>
<div style="clear: both"></div>
<p>When I started implementing <a href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html">mod_rewrite</a> in websites I had a problem in <a href="http://php.net">PHP</a> as how to make a SEO friendly URL. All tutorials were geared towards how to implement mod_rewrite, about modifying .htaccess files, but none treated how to make the urls friendly with dynamic content. For example I have a news section which are pulled from the database, but how can I make the  URL friendly with the title.<br />
<span id="more-24"></span><br />
For example, my problem was to convert titles like "Barca rejects FIFA statement on Olympics row" into "barca-rejects-fifa-statement-on-olympics-row.html". The trick has to work also with french titles (I'am sure my friends at <a href="http://www.nexen.net">Nexen</a> will appreciate ;-)) like "Guantanamo: le chauffeur de Ben Laden plaide non coupable à l'ouverture de son procès" into "guantanamo-le-chauffeur-de-ben-laden-plaide-non-coupable-a-l-ouverture-de-son-proces.html", removing all french accentuated characters.</p>
<p>Hopefully I came across this function which I think might help you too :</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> friendlyURL<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$string</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #0000ff;">$string</span> = <a href="http://www.php.net/preg_replace"><span style="color: #000066;">preg_replace</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;`<span style="color: #000099; font-weight: bold;">\[</span>.*<span style="color: #000099; font-weight: bold;">\]</span>`U&quot;</span>,<span style="color: #ff0000;">&quot;&quot;</span>,<span style="color: #0000ff;">$string</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0000ff;">$string</span> = <a href="http://www.php.net/preg_replace"><span style="color: #000066;">preg_replace</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'`&amp;(amp;)?#?[a-z0-9]+;`i'</span>,<span style="color: #ff0000;">'-'</span>,<span style="color: #0000ff;">$string</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0000ff;">$string</span> = <a href="http://www.php.net/htmlentities"><span style="color: #000066;">htmlentities</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$string</span>, ENT_COMPAT, <span style="color: #ff0000;">'utf-8'</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0000ff;">$string</span> = <a href="http://www.php.net/preg_replace"><span style="color: #000066;">preg_replace</span></a><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;`&amp;([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig|quot|rsquo);`i&quot;</span>,<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>1&quot;</span>, <span style="color: #0000ff;">$string</span> <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0000ff;">$string</span> = <a href="http://www.php.net/preg_replace"><span style="color: #000066;">preg_replace</span></a><span style="color: #66cc66;">&#40;</span> <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;`[^a-z0-9]`i&quot;</span>,<span style="color: #ff0000;">&quot;`[-]+`&quot;</span><span style="color: #66cc66;">&#41;</span> , <span style="color: #ff0000;">&quot;-&quot;</span>, <span style="color: #0000ff;">$string</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">return</span> <a href="http://www.php.net/strtolower"><span style="color: #000066;">strtolower</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/trim"><span style="color: #000066;">trim</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$string</span>, <span style="color: #ff0000;">'-'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>Use :</p>
<pre class="php">&nbsp;
<span style="color: #0000ff;">$myFriendlyURL</span> = friendlyURL<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Barca rejects FIFA statement on Olympics row&quot;</span><span style="color: #66cc66;">&#41;</span>;
<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$myFriendlyURL</span>; <span style="color: #808080; font-style: italic;">// will echo barca-rejects-fifa-statement-on-olympics-row</span>
&nbsp;</pre>
<p>You just have to concatenate anything you want with the string afterwards. For french users, make sure your string is encoded in UTF-8 else it won't work.</p>
<p>If you're using the <a href="http://smarty.php.net">Smarty templating engine</a> I made a little <a href="http://www.smarty.net/manual/en/language.modifiers.php">modifier</a> which you can <a href="http://htmlblog.net/wp-content/uploads/2008/07/modifierfriendlyurl.zip">download</a>. Extract the zip file in your Smarty/libs/plugins/ folder and to use it in your templates :</p>
<pre>&nbsp;
{&quot;Barca rejects FIFA statement on Olympics row&quot; | friendlyURL}
&nbsp;</pre>
<p>Or if your string is in a variable :</p>
<pre>&nbsp;
{$yourString | friendlyURL}
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/seo-friendly-url-in-php/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>10 starting signs of a good web developer (php version)</title>
		<link>http://htmlblog.net/10-starting-signs-of-good-web-developers-php-version/</link>
		<comments>http://htmlblog.net/10-starting-signs-of-good-web-developers-php-version/#comments</comments>
		<pubDate>Sat, 05 Jul 2008 10:03:33 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[good]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[practice]]></category>
		<category><![CDATA[smarty]]></category>
		<category><![CDATA[standards]]></category>
		<category><![CDATA[templating]]></category>
		<category><![CDATA[w3c]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[web developer]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=10</guid>
		<description><![CDATA[

Nowadays many people call themselves PHP programmers / web developers as soon as they know a bit of Frontpage or using Dreamweaver to generate the code for them. But are they really good web developers? Here's my top 10 characteristics of good web developers, feel free to comment.

1. Ability to hand code
Instead of using an [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://farm1.static.flickr.com/75/158927067_86bcadf62f.jpg?v=0" alt="web developer" /></p>
<div style="clear: both"></div>
<p>Nowadays many people call themselves PHP programmers / web developers as soon as they know a bit of Frontpage or using Dreamweaver to generate the code for them. But are they really good web developers? Here's my top 10 characteristics of good web developers, feel free to comment.<br />
<span id="more-10"></span><br />
<strong>1. Ability to hand code</strong><br />
Instead of using an IDE where it justs generate a bunch of lines which you don't understand, why you don't fire up a text editor such as VI, Emacs, Notepad or Notepad++ if you prefer and start coding right away? There are many advantages of hand coding HTML.</p>
<ul>
<li>The code is clean</li>
<li>You understand what you're doing</li>
<li>Easy maintenance and debugging.</li>
</ul>
<p><a href='http://www.eclipse.org/pdt/'><img src="http://htmlblog.net/wp-content/uploads/2008/07/eclipse.jpg" alt="" title="eclipse" width="131" height="68" class="alignnone size-full wp-image-11" /></a></p>
<div style="clear: both"></div>
<p>I currently use <a href="http://www.eclipse.org/pdt/">Eclipse PDT as IDE</a></p>
<div style="clear: both"></div>
<p><br/><br />
<strong>2. Ability to produce valid HTML.</strong><br />
The <a href="http://validator.w3.org/">W3C has an online tool</a> which checks whether the HTML code you write is valid or not and there's a debate whether your code must valid or not. IMHO they must be and that's why :</p>
<ul>
<li>Future proof</li>
<li>Cross browser compatibilities</li>
<li>Easier to maintain</li>
</ul>
<p><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /><br />
<a href="http://validator.w3.org/">Validate your code</a></p>
<div style="clear: both"></div>
<p><br/><br />
<strong>3. Use Linux as operating system</strong><br />
Why on earth a web developer doesn't use Linux? It's free, comes with bunch of applications, you know the internals, you compile from source, you experiment things and most important, you're more productive. An example, I must edit a file on server A.<br />
On Windows :<br />
Launch WinSCP -> connect to server A -> retrieve file -> edit file -> save -> upload -> ask for confirmation -> wait upload finish</p>
<p>On Linux:<br />
Launch console -> SSH on server A -> open file in VI for editing -> save</p>
<p>Enough said ;-)</p>
<p><a href='http://kubuntu.org'><img src="http://htmlblog.net/wp-content/uploads/2008/07/kubuntu-header.png" alt="" title="kubuntu-header" width="450" height="90" class="alignnone size-full wp-image-12" /></a></p>
<div style="clear: both"></div>
<p>I currently use <a href="http://kubuntu.org">Kubuntu (Hardy Heron)</a></p>
<div style="clear: both"></div>
<p><br/><br />
<strong>4. Templating</strong><br />
Have you heard of spaghetti code? If not, it's mixing PHP code with HTML code. For example :</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">&lt;body&gt;</span></a></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span>?php echo <span style="color: #ff0000;">'hi'</span>; ?<span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body&gt;</span></span>
&nbsp;</pre>
<p>This results in nightmare maintenance, a mess of code. Both designer and web developer work in the same file which is a bad mixture of logic and presentation. Fortunately there are templating engines which separate these two things.<br />
<a href='http://smarty.php.net'><img src="http://htmlblog.net/wp-content/uploads/2008/07/smarty-logo-orange.gif" alt="" title="smarty-logo-orange" width="250" height="64" class="alignnone size-full wp-image-13" /></a></p>
<p>The most popular one being <a href="http://smarty.php.net">Smarty </a>which I currently use. Have the <a href="http://www.smarty.net/crashcourse.php">crash course</a> if you haven't already.</p>
<div style="clear: both"></div>
<p><br/><br />
<strong>5. Database abstraction layer</strong><br />
Your scripts must be database independent, i.e. if tomorrow your boss decides to throw all <a href="http://www.mysql.com/">MySQL </a>away and replace them by <a href="http://www.postgresql.org/">PostgreSQL</a>, you don't have to write the scripts all again replacing all MySQL functions by PostgreSQL one. Also, you just have to learn a single API.</p>
<p>I use <a href="http://pear.php.net/package/MDB2">PEAR MDB2 </a>as DB abstraction library.</p>
<div style="clear: both"></div>
<p><br/><br />
<strong>6. JS framework</strong><br />
Javascript is everywhere nowadays together with the AJAX buzz word. Good web developers must have an overview of all the js frameworks available and choose the best one for his task. Popular frameworks include the <a href="http://developer.yahoo.com/yui/">YUI library</a>,<a href="http://www.prototypejs.org/"> Prototype</a>, <a href="http://jquery.com/">jQuery</a>, <a href="http://mootools.net/">MooTools</a>, <a href="http://dojotoolkit.org/">Dojo Toolkit</a> and <a href="http://extjs.com/">Ext JS</a> to name just a few.</p>
<p><a href='http://developer.yahoo.com/yui/'><img src="http://htmlblog.net/wp-content/uploads/2008/07/yuilib.jpg" alt="" title="yuilib" width="260" height="161" class="alignnone size-full wp-image-14" /></a></p>
<p>I prefer <a href="http://developer.yahoo.com/yui/">YUI library</a> (lots of documentation and exciting future)</p>
<div style="clear: both"></div>
<p><br/><br />
<strong>7. Caching</strong><br />
Why retrieving the same information from the database again and again whereas you can cache the output to files or in memory. This will reduce the load on your database server. If you use the Smarty templating engine you can use <a href="http://www.smarty.net/manual/en/caching.groups.php">cache groups </a>. Another popular technique is by using <a href="http://www.danga.com/memcached/">Memcache</a>, for high volume websites.</p>
<p>At work I use the Smarty caching system and a little bit of Memcache (for the taste ;-)), and my database load reduced by more than 70%.</p>
<div style="clear: both"></div>
<p><br/><br />
<strong>8. Must have Firefox extensions : Firebug, web developer toolbar, YSlow</strong><br />
<a href='http://www.getfirebug.com/'><img src="http://htmlblog.net/wp-content/uploads/2008/07/firebug.png" alt="" title="firebug" width="500" height="104" class="alignnone size-full wp-image-16" /></a></p>
<div style="clear: both"></div>
<p>These great firefox extensions will help you greatly whether to debug some javascript, fix some CSS issues, increase your site performance. These are must-have for web developers, all three of them.</p>
<ul>
<li><a href="http://www.getfirebug.com/">Firebug</a></li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/60">Web developer</a></li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/5369">YSlow!</a></li>
</ul>
<div style="clear: both"></div>
<p><br/><br />
<strong>9. Keep reading</strong><br />
Keep reading reading and reading. Find popular programming posts on <a href="http://digg.com">Digg</a>, <a href="http://del.icio.us/popular/">del.icio.us</a> and read great magazines like <a href="http://www.smashingmagazine.com/">Smashing Magazine</a>, blogs like the <a href="http://yuiblog.com">YUI blog</a>. Don't forget to participate actively in forums and ask questions.</p>
<p><a href='http://del.icio.us/popular'><img src="http://htmlblog.net/wp-content/uploads/2008/07/delicious42px.gif" alt="" title="delicious42px" width="42" height="42" class="alignnone size-full wp-image-15" /></a></p>
<p>I don't know why it's like that but I like <a href="http://del.icio.us/popular">del.icio.us popular</a> section more interesting and everyday I find lots of interesting stuff via this page.</p>
<div style="clear: both"></div>
<p><br/><br />
<strong>10. Look around you</strong><br />
<a href='http://www.rubyonrails.org/'><img src="http://htmlblog.net/wp-content/uploads/2008/07/rails.png" alt="" title="rails" width="87" height="112" class="alignnone size-full wp-image-17" /></a><br />
Don't focus only on PHP. It's OK but have a look around you, there are fantastic things happening, like <a href="http://www.rubyonrails.org/">RoR</a>, Python ;-)<br />
A web developer who hasn't heard of RoR is NOT a good web developer.</p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/10-starting-signs-of-good-web-developers-php-version/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
