<?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>communication &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/communication/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>PHP: Does SimpleXMLElement have toString() method? No, better use asXML()!</title>
		<link>/2011/10/10/php-does-simplexmlelement-have-tostring-method-no-better-use-asxml/</link>
		<comments>/2011/10/10/php-does-simplexmlelement-have-tostring-method-no-better-use-asxml/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 11:52:49 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[Computer file formats]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Markup languages]]></category>
		<category><![CDATA[Open formats]]></category>
		<category><![CDATA[OSI protocols]]></category>
		<category><![CDATA[Technical communication]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">/?p=2362</guid>
		<description><![CDATA[SimpleXML is a PHP extension that &#8220;provides a very simple and easily usable toolset to convert XML to an object&#8221; [1]. Thus you can pass a link to an XML file and SimpleXML will return an object. $xml = simplexml_load_file('path_to_the_file'); Sometimes you&#8217;d need to dump or save the entire XML as a string, but there’s &#8230; <a href="/2011/10/10/php-does-simplexmlelement-have-tostring-method-no-better-use-asxml/" class="more-link">Continue reading <span class="screen-reader-text">PHP: Does SimpleXMLElement have toString() method? No, better use asXML()!</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/07/29/php-strings-how-to-get-the-extension-of-a-file/" rel="bookmark" title="PHP Strings: How to Get the Extension of a File">PHP Strings: How to Get the Extension of a File </a></li>
<li><a href="/2010/04/20/how-to-sanitize-user-input-in-php/" rel="bookmark" title="How to Sanitize User Input in PHP?">How to Sanitize User Input in PHP? </a></li>
<li><a href="/2010/07/14/media-rss-and-zf-part-2/" rel="bookmark" title="Media RSS and ZF &#8211; Part 2">Media RSS and ZF &#8211; Part 2 </a></li>
<li><a href="/2011/10/20/some-notes-on-the-object-oriented-model-of-php/" rel="bookmark" title="Some Notes on the Object-oriented Model of PHP">Some Notes on the Object-oriented Model of PHP </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>SimpleXML is a PHP extension that &#8220;provides a very simple and easily usable toolset to convert XML to an object&#8221; [1]. Thus you can pass a link to an XML file and SimpleXML will return an object.</p>
<pre lang="php">$xml = simplexml_load_file('path_to_the_file');</pre>
<p>Sometimes you&#8217;d need to dump or save the entire XML as a string, but there’s no toString method! As you can see $xml is an instance of the SimpleXMLElement class.</p>
<pre lang="php">var_dump($xml); // object(SimpleXMLElement)...</pre>
<p>Actually if you take a closer look:</p>
<pre lang="php">$xml->toString();</pre>
<p>will return <strong>&#8220;Call to an undefined method toString()&#8221;</strong>, which is frustrating because the developers community is used to use toString() when converting an object into a string.</p>
<figure id="attachment_2395" style="width: 448px" class="wp-caption aligncenter"><a href="/wp-content/uploads/2011/10/XML.jpg"><img src="/wp-content/uploads/2011/10/XML.jpg" alt="XML" title="XML" width="448" height="269" class="size-full wp-image-2395" srcset="/wp-content/uploads/2011/10/XML.jpg 448w, /wp-content/uploads/2011/10/XML-300x180.jpg 300w" sizes="(max-width: 448px) 100vw, 448px" /></a><figcaption class="wp-caption-text">PHP&#039;s SimpleXML doesn&#039;t have toString() method. asXML() is used instead!</figcaption></figure>
<h2>The solution</h2>
<p>In fact there’s a method doing exactly what’s needed. This is <a title="SimpleXMLElement::asXML()" href="http://www.php.net/manual/en/simplexmlelement.asxml.php" target="_blank">SimpleXMLElement::asXML</a></p>
<p>As described in the manual page: &#8220;SimpleXMLElement::asXML — Return a well-formed XML string based on SimpleXML element&#8221; [2].</p>
<p>Besides that it does exactly what&#8217;s needed it sounds irrelevant, because you&#8217;ve an XML object and the name &#8220;asXML&#8221; doesn&#8217;t describe correctly what&#8217;s expected.</p>
<pre lang="php">$xml->asXML() // ?!</pre>
<ol>
<li><a title="SimpleXMLElement::asXML" href="http://www.php.net/manual/en/intro.simplexml.php" target="_blank">SimpleXMLElement::asXML</a></li>
<li><a title="SimpleXML Introduction" href="http://www.php.net/manual/en/intro.simplexml.php" target="_blank">SimpleXML Introduction</a></li>
</ol>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/07/29/php-strings-how-to-get-the-extension-of-a-file/" rel="bookmark" title="PHP Strings: How to Get the Extension of a File">PHP Strings: How to Get the Extension of a File </a></li>
<li><a href="/2010/04/20/how-to-sanitize-user-input-in-php/" rel="bookmark" title="How to Sanitize User Input in PHP?">How to Sanitize User Input in PHP? </a></li>
<li><a href="/2010/07/14/media-rss-and-zf-part-2/" rel="bookmark" title="Media RSS and ZF &#8211; Part 2">Media RSS and ZF &#8211; Part 2 </a></li>
<li><a href="/2011/10/20/some-notes-on-the-object-oriented-model-of-php/" rel="bookmark" title="Some Notes on the Object-oriented Model of PHP">Some Notes on the Object-oriented Model of PHP </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/10/10/php-does-simplexmlelement-have-tostring-method-no-better-use-asxml/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Send Html Mails with Zend_Mail</title>
		<link>/2010/07/17/send-html-mails-with-zend_mail/</link>
		<comments>/2010/07/17/send-html-mails-with-zend_mail/#respond</comments>
		<pubDate>Sat, 17 Jul 2010 11:31:47 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[E-mail]]></category>
		<category><![CDATA[Form]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[Spamming]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[web system]]></category>
		<category><![CDATA[World Wide Web]]></category>

		<guid isPermaLink="false">/?p=1815</guid>
		<description><![CDATA[Typically you&#8217;d never like to send a non-html formatted mail from your web system. It&#8217;s ugly and it&#8217;s difficult to read. Instead of sending pure text, you&#8217;d like to add some images and styles. The way you can do it with Zend_Mail is simple enough. Replace the setBody method with setBodyHtml. Isn&#8217;t that natural? // &#8230; <a href="/2010/07/17/send-html-mails-with-zend_mail/" class="more-link">Continue reading <span class="screen-reader-text">Send Html Mails with Zend_Mail</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/03/25/send-mail-with-zend-framework/" rel="bookmark" title="Send Mail with Zend Framework">Send Mail with Zend Framework </a></li>
<li><a href="/2010/07/18/zend_mail-with-gmail/" rel="bookmark" title="Zend_Mail with GMail">Zend_Mail with GMail </a></li>
<li><a href="/2010/06/28/send-authenticated-post-request-with-zend_http_client/" rel="bookmark" title="Send Authenticated POST Request with Zend_Http_Client">Send Authenticated POST Request with Zend_Http_Client </a></li>
<li><a href="/2010/01/12/faster-html-why-not/" rel="bookmark" title="Faster HTML! Why not?">Faster HTML! Why not? </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p><a href="/wp-content/uploads/2010/07/mails.jpg"><img src="/wp-content/uploads/2010/07/mails.jpg" alt="Zend_Mail" title="mails" width="430" height="276" class="aligncenter size-full wp-image-1822" srcset="/wp-content/uploads/2010/07/mails.jpg 430w, /wp-content/uploads/2010/07/mails-300x192.jpg 300w" sizes="(max-width: 430px) 100vw, 430px" /></a><br />
Typically you&#8217;d never like to send a non-html formatted mail from your web system. It&#8217;s ugly and it&#8217;s difficult to read. Instead of sending pure text, you&#8217;d like to add some images and styles. The way you can do it with Zend_Mail is simple enough. Replace the setBody method with setBodyHtml. Isn&#8217;t that natural?</p>
<pre lang="php">
// before
$mail = new Zend_Mail('utf-8');
$mail->setFrom('sender@example.com', 'Sender Name');
$mail->setBody('message in Html');
$mail->addTo('recipient@example.com', 'Recepient Name');
$mail->setSubject('Subject');
$mail->send();
</pre>
<pre lang="php">
// after
$mail = new Zend_Mail('utf-8');
$mail->setFrom('sender@example.com', 'Sender Name');
$mail->setBodyHtml('message in Html');
$mail->addTo('recipient@example.com', 'Recepient Name');
$mail->setSubject('Subject');
$mail->send();
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/03/25/send-mail-with-zend-framework/" rel="bookmark" title="Send Mail with Zend Framework">Send Mail with Zend Framework </a></li>
<li><a href="/2010/07/18/zend_mail-with-gmail/" rel="bookmark" title="Zend_Mail with GMail">Zend_Mail with GMail </a></li>
<li><a href="/2010/06/28/send-authenticated-post-request-with-zend_http_client/" rel="bookmark" title="Send Authenticated POST Request with Zend_Http_Client">Send Authenticated POST Request with Zend_Http_Client </a></li>
<li><a href="/2010/01/12/faster-html-why-not/" rel="bookmark" title="Faster HTML! Why not?">Faster HTML! Why not? </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/07/17/send-html-mails-with-zend_mail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>document.forms[&#8216;myform&#8217;].submit() is not a function?</title>
		<link>/2010/07/05/document-formsmyform-submit-is-not-a-function/</link>
		<comments>/2010/07/05/document-formsmyform-submit-is-not-a-function/#comments</comments>
		<pubDate>Mon, 05 Jul 2010 19:11:12 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Form]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[World Wide Web]]></category>

		<guid isPermaLink="false">/?p=1751</guid>
		<description><![CDATA[.submit() You want to submit the form by clicking on a link or some other element on the page and this is a simple task. You know that by simply adding something like document.forms[&#8216;the-form-name&#8217;].submit() this will work. Submit However you&#8217;d like to submit the form not only by clicking on that particular element, but also &#8230; <a href="/2010/07/05/document-formsmyform-submit-is-not-a-function/" class="more-link">Continue reading <span class="screen-reader-text">document.forms[&#8216;myform&#8217;].submit() is not a function?</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/04/09/secure-forms-with-zend-framework/" rel="bookmark" title="Secure Forms with Zend Framework">Secure Forms with Zend Framework </a></li>
<li><a href="/2010/04/25/detecting-post-requests-in-zend-framework/" rel="bookmark" title="Detecting POST Requests in Zend Framework">Detecting POST Requests in Zend Framework </a></li>
<li><a href="/2010/06/04/one-form-multiple-db-records/" rel="bookmark" title="One Form &#8211; Multiple DB Records">One Form &#8211; Multiple DB Records </a></li>
<li><a href="/2011/11/23/how-to-setup-different-error-messages-for-each-zend-form-element-validator/" rel="bookmark" title="How to Setup Different Error Messages for Each Zend Form Element Validator">How to Setup Different Error Messages for Each Zend Form Element Validator </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>.submit()</h2>
<p>You want to submit the form by clicking on a link or some other element on the page and this is a simple task. You know that by simply adding something like <strong>document.forms[&#8216;the-form-name&#8217;].submit()</strong> this will work.</p>
<pre lang="html4strict">
<form method="post" name="myform">
    <input type="text" name="user" />
    <a href="#" onclick="document.forms['myform'].submit();return false">Submit</a>
</form>
</pre>
<p>However you&#8217;d like to submit the form not only by clicking on that particular element, but also by clicking on the Enter while the focus is on a input field, and this wont work! That&#8217;s because you don&#8217;t have a input type=&#8221;submit&#8221;.</p>
<p>OK, first thing is to add a hidden input type=&#8221;submit&#8221; &#8211; than by clicking both on the Enter keyboard button and on the link with the onclick=&#8221;document.blah.blah.blah&#8221; will submit the form.</p>
<pre lang="html4strict">
<form method="post" name="myform">
    <input type="text" name="user" />
    <input type="submit" name="submit" value="submit" style="display:hidden" />
    <a href="#" onclick="document.forms['myform'].submit();return false">Submit</a>
</form>
</pre>
<h2>But this is not true!</h2>
<p>Than you&#8217;ll receive the following message:</p>
<pre>document.forms['myform'].submit() is not a function</pre>
<p>Why? This isn&#8217;t working, but ever line seems to be OK. The answer is &#8211; don&#8217;t name the input type=&#8221;submit&#8221; with the trivial &#8211; &#8220;submit&#8221;. Just give it another name:</p>
<pre lang="html4strict">
<form method="post" name="myform">
    <input type="text" name="user" />
    <input type="submit" name="something" value="something" style="display:hidden" />
    <a href="#" onclick="document.forms['myform'].submit();return false">Submit</a>
</form>
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/04/09/secure-forms-with-zend-framework/" rel="bookmark" title="Secure Forms with Zend Framework">Secure Forms with Zend Framework </a></li>
<li><a href="/2010/04/25/detecting-post-requests-in-zend-framework/" rel="bookmark" title="Detecting POST Requests in Zend Framework">Detecting POST Requests in Zend Framework </a></li>
<li><a href="/2010/06/04/one-form-multiple-db-records/" rel="bookmark" title="One Form &#8211; Multiple DB Records">One Form &#8211; Multiple DB Records </a></li>
<li><a href="/2011/11/23/how-to-setup-different-error-messages-for-each-zend-form-element-validator/" rel="bookmark" title="How to Setup Different Error Messages for Each Zend Form Element Validator">How to Setup Different Error Messages for Each Zend Form Element Validator </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/07/05/document-formsmyform-submit-is-not-a-function/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>How to Sanitize User Input in PHP?</title>
		<link>/2010/04/20/how-to-sanitize-user-input-in-php/</link>
		<comments>/2010/04/20/how-to-sanitize-user-input-in-php/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 12:03:26 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Form]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[Markup languages]]></category>
		<category><![CDATA[Technical communication]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[World Wide Web]]></category>

		<guid isPermaLink="false">/?p=1461</guid>
		<description><![CDATA[It&#8217;s a question almost every PHP developer asks yourself. By me the most simple way to sanitize the user input is to save everything in the database with no loosing of tags or whatever HTML markup and than on displaying this on the client side to strip_tags if needed. In example when saving a HTML &#8230; <a href="/2010/04/20/how-to-sanitize-user-input-in-php/" class="more-link">Continue reading <span class="screen-reader-text">How to Sanitize User Input in PHP?</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/02/25/how-to-collect-the-images-and-meta-tags-from-a-webpage-with-php/" rel="bookmark" title="How to Collect the Images and Meta Tags from a Webpage with PHP">How to Collect the Images and Meta Tags from a Webpage with PHP </a></li>
<li><a href="/2010/09/10/automatically-upload-images-with-php-directly-from-the-uri/" rel="bookmark" title="Automatically Upload Images with PHP Directly from the URI">Automatically Upload Images with PHP Directly from the URI </a></li>
<li><a href="/2010/03/10/php-if-else-endif-statements/" rel="bookmark" title="PHP if-else-endif Statements">PHP if-else-endif Statements </a></li>
<li><a href="/2011/02/09/wanted-onfocusonblur-why-they-dont-work-always/" rel="bookmark" title="Wanted &#8211; onfocus/onblur. Why They Don&#8217;t Work Always!">Wanted &#8211; onfocus/onblur. Why They Don&#8217;t Work Always! </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>It&#8217;s a question almost every PHP developer asks yourself. By me the most simple way to sanitize the user input is to save everything in the database with no loosing of tags or whatever HTML markup and than on displaying this on the client side to strip_tags if needed.</p>
<p>In example when saving a HTML formatted text you can use simply the htmlspecialchars method</p>
<pre lang="php">$description = htmlspecialchars($_POST['description']);</pre>
<p>Than you can be sure everything&#8217;s in the database, but it&#8217;s not actually HTML. Thus you don&#8217;t have any tags at all in the database field.</p>
<p>When you show this in the client side and you&#8217;d like to strip some tags, i.e. to keep only the &lt;a&gt; tag you can do this:</p>
<pre lang="php" escaped="true">echo strip_tags(htmlspecialchars_decode($description), '&lt;a&gt;');</pre>
<p>That&#8217;s the most simple way to keep everything as the original source. By me it&#8217;s better to keep whatever HTML markup there is on the input.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/02/25/how-to-collect-the-images-and-meta-tags-from-a-webpage-with-php/" rel="bookmark" title="How to Collect the Images and Meta Tags from a Webpage with PHP">How to Collect the Images and Meta Tags from a Webpage with PHP </a></li>
<li><a href="/2010/09/10/automatically-upload-images-with-php-directly-from-the-uri/" rel="bookmark" title="Automatically Upload Images with PHP Directly from the URI">Automatically Upload Images with PHP Directly from the URI </a></li>
<li><a href="/2010/03/10/php-if-else-endif-statements/" rel="bookmark" title="PHP if-else-endif Statements">PHP if-else-endif Statements </a></li>
<li><a href="/2011/02/09/wanted-onfocusonblur-why-they-dont-work-always/" rel="bookmark" title="Wanted &#8211; onfocus/onblur. Why They Don&#8217;t Work Always!">Wanted &#8211; onfocus/onblur. Why They Don&#8217;t Work Always! </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/04/20/how-to-sanitize-user-input-in-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CSS sprites. Go beyond the limits with base64!</title>
		<link>/2010/02/05/css-sprites-go-beyond-the-limits-with-base64/</link>
		<comments>/2010/02/05/css-sprites-go-beyond-the-limits-with-base64/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 08:10:29 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[base64]]></category>
		<category><![CDATA[Cascading Style Sheets]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Data URI scheme]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[Minification]]></category>
		<category><![CDATA[sprite]]></category>
		<category><![CDATA[Stoyan Stefanov]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[URI scheme]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[Web page]]></category>
		<category><![CDATA[web projects]]></category>
		<category><![CDATA[web server]]></category>
		<category><![CDATA[World Wide Web]]></category>

		<guid isPermaLink="false">/?p=1055</guid>
		<description><![CDATA[Why should I optimize CSS? In fact how and why should I optimize CSS is the right question. Actually CSS is simply one ore more files loaded from the server to the client, usually a browser, with CSS specific rules that must be applied by the browser to the web page you&#8217;re seeing. That&#8217;s in &#8230; <a href="/2010/02/05/css-sprites-go-beyond-the-limits-with-base64/" class="more-link">Continue reading <span class="screen-reader-text">CSS sprites. Go beyond the limits with base64!</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2009/04/23/when-you-should-use-base64-for-images/" rel="bookmark" title="When you should use base64 for images">When you should use base64 for images </a></li>
<li><a href="/2010/01/30/optimizing-css-five-simple-steps/" rel="bookmark" title="Optimizing CSS. Five simple steps!">Optimizing CSS. Five simple steps! </a></li>
<li><a href="/2010/01/13/optimizing-the-web-start-with-the-images/" rel="bookmark" title="Optimizing the web. Start with the images!">Optimizing the web. Start with the images! </a></li>
<li><a href="/2011/01/07/more-on-css-optimization/" rel="bookmark" title="More on CSS Optimization">More on CSS Optimization </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Why should I optimize CSS?</h2>
<p>In fact how and why should I optimize CSS is the right question. Actually CSS is simply one ore more files loaded from the server to the client, usually a browser, with CSS specific rules that must be applied by the browser to the web page you&#8217;re seeing. That&#8217;s in general. Of course there are exceptions when CSS can be inline or added directly to the HTML tags, which is bad practice because thus the HTML markup becomes larger and even worse the browser cannot cache it and than load it quickly. In fact that&#8217;s why usually the CSS of a web page is put in one single file. Primary because that makes only one request to the server and in second hand because it can be cached by the browser.</p>
<p>Just because the nature of the CSS is that firstly it&#8217;s loaded and than executed one of the primary techniques of optimizing it is to make it smaller and therefore load faster. There are several methods of doing so. Enabling GZIP support of the web server and minifying the file are the most common ones. But one of the tricks you cannot optimizing just for second is using the so called CSS sprites.</p>
<h2>CSS sprites</h2>
<p>What are these? To answer this question I&#8217;ll simply try to give you an example. Let&#8217;s assume there are three CSS classes each one with its own background image. This makes four requests to the server. One for the CSS file and one per every background image. But what we&#8217;d like to achieve is to make less requests as we can. Than one of the things we can do is to make one single image and to change only the background-position CSS property to position it on the right place and to make it appear correctly.</p>
<p>Be careful! When you join all of the images into one single CSS sprite you may add one class with that background-image and every other class with only background-position property. Than every DOM element with that background must have both class names. Only than you can be sure the server will make two requests. One for the CSS file and one for the sprite.</p>
<h2>base64 to encode images</h2>
<p>In other hand most of the web projects are pretty big, and unfortunately it&#8217;s too difficult to make only one single sprite just because it&#8217;s too difficult to manage it after the project has become very large. That&#8217;s why mostly in the practice there are several sprites for the main components. But the problem is that again there are more HTTP requests.</p>
<h3>Is there any way to make only one request?</h3>
<p>Yes there is. Simply by converting your CSS sprite into a base64 encoded image. In breve base64 is an encoding where you can practically make any data into a string. Thus the image can be represented by a string containing the same information as the image. Hopefully most of the browser, except of course MSIE, does read the so called data urls, or:</p>
<blockquote>
<pre>&lt;img src="data:image/png;base64,..... " /&gt;</pre>
</blockquote>
<p>and that&#8217;s enough to get started with base64 and the single request. The sprite has become a string!</p>
<h2>CSS and base64</h2>
<p>The natural question is now how to merge all this? You now have one CSS file with one or more sprites. Than you can convert them into a base64 encoded strings and put them all into the CSS.</p>
<p>There is a problem, of course, what happens with MSIE. As I said before MSIE doesn&#8217;t read base64 encoded images. Hopefully there is a solution described very well by <a href="http://phpied.com/" target="_blank">Stoyan Stefanov</a> in his <a href="http://www.phpied.com/data-uris-mhtml-ie7-win7-vista-blues/" target="_blank">blog post here</a>.</p>
<h2>Finally &#8230;</h2>
<p>now there is only one request and everything works pretty fine. This technique can be really helpful to someone who&#8217;s trying to optimize the CSS performance to the limits.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2009/04/23/when-you-should-use-base64-for-images/" rel="bookmark" title="When you should use base64 for images">When you should use base64 for images </a></li>
<li><a href="/2010/01/30/optimizing-css-five-simple-steps/" rel="bookmark" title="Optimizing CSS. Five simple steps!">Optimizing CSS. Five simple steps! </a></li>
<li><a href="/2010/01/13/optimizing-the-web-start-with-the-images/" rel="bookmark" title="Optimizing the web. Start with the images!">Optimizing the web. Start with the images! </a></li>
<li><a href="/2011/01/07/more-on-css-optimization/" rel="bookmark" title="More on CSS Optimization">More on CSS Optimization </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/02/05/css-sprites-go-beyond-the-limits-with-base64/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Flex Javascript communcation example</title>
		<link>/2009/03/09/flex-javascript-communcation-example/</link>
		<comments>/2009/03/09/flex-javascript-communcation-example/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 06:59:29 +0000</pubDate>
		<dc:creator><![CDATA[stoimen]]></dc:creator>
				<category><![CDATA[featured]]></category>
		<category><![CDATA[flex 3]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[ExternalInterface]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">/?p=305</guid>
		<description><![CDATA[Here's a short sample, showing how to set up communication between JavaScript and Flex.<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2009/03/07/flex-javascript-communication/" rel="bookmark" title="Flex Javascript communication">Flex Javascript communication </a></li>
<li><a href="/2009/10/29/passing-objects-with-externalinterface-from-js-to-flex/" rel="bookmark" title="Passing objects with ExternalInterface from JS to Flex">Passing objects with ExternalInterface from JS to Flex </a></li>
<li><a href="/2009/07/08/externalinterface-from-javascript-to-ie-firefox/" rel="bookmark" title="ExternalInterface from JavaScript to IE/Firefox">ExternalInterface from JavaScript to IE/Firefox </a></li>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>First of all you&#8217;ve to have both files for JavaScript and Actionscript  3 to make the communication successful. I don&#8217;t remember where exactly I found the tutorial, maybe it was on the official Adobe&#8217;s documentation page, but as I&#8217;ve <a title="javascript to flex communcation with externalInterface" href="/2009/03/07/flex-javascript-communication/" target="_self">written</a> before I&#8217;m going to share my experience with the ExternalInterface options of Flex.</p>
<p>First of all you&#8217;ve to add this at the beginning of the page with the simple js code:</p>
<blockquote><p><span style="color: #808080;"><em>var jsReady = false;<br />
function isReady()<br />
{<br />
return jsReady;<br />
}</em></span></p>
<p><em>function pageInit()<br />
{<br />
jsReady = true;<br />
}</em></p></blockquote>
<p>of course the <strong>pageInit()</strong> function should be called <em><strong>onload</strong></em> of the body. It simply sets the JavaScript part to be ready for communication, after initialize the page. Than a small part of the javascript should be written for really speaking with the Flex application.</p>
<blockquote><p><span style="color: #808080;"><em>var swfReady = false;</em></span></p>
<p><em>function setSWFIsReady() {<br />
swfReady = true;<br />
}</em></p>
<p><em>function getSWF(movieName) {<br />
if (navigator.appName.indexOf(&#8220;Microsoft&#8221;) != -1) {<br />
return window[movieName];<br />
} else {<br />
return document[movieName];<br />
}<br />
}</em></p>
<p><em>function callFlexApp() {<br />
if (swfReady) {<br />
getSWF(&#8220;flash_movie&#8221;).methodInFlex(param_value1, param_value2);<br />
}<br />
}</em></p></blockquote>
<p>Where <em><strong>flash_movie</strong></em> is the id of the object / embed pair.</p>
<p>First of all the JavaScript can begin to call methods in Flex only after the Flex application has returned that it has been initialized. That happens in Flex within the following file:</p>
<blockquote><p><span style="color: #808080;"><em>package communicator {</em></span></p>
<p><em>import flash.events.TimerEvent;<br />
import flash.external.*;<br />
import flash.utils.Timer;</em></p>
<p><em>public class Communicator<br />
{</em></p>
<p><em>public function init():void {</em></p>
<p><em>if (ExternalInterface.available)<br />
{</em></p>
<p><em>var containerReady:Boolean = isContainerReady();<br />
if (containerReady)<br />
{<br />
setupCallbacks();<br />
}<br />
else<br />
{<br />
var readyTimer:Timer = new Timer(100);<br />
readyTimer.addEventListener(TimerEvent.TIMER, timerHandler);<br />
readyTimer.start();<br />
}</em></p>
<p><em>}<br />
else<br />
{<br />
trace(&#8220;External interface is not available for this container.&#8221;);<br />
}</em></p>
<p><em>}</em></p>
<p><em>private function isContainerReady():Boolean<br />
{<br />
var result:Boolean = ExternalInterface.call(&#8220;isReady&#8221;);<br />
return result;<br />
}</em></p>
<p><em>private function setupCallbacks():void<br />
{<br />
ExternalInterface.addCallback(&#8220;callFlexApp&#8221;, callFlexApp);<br />
ExternalInterface.call(&#8220;setSWFIsReady&#8221;);<br />
}</em></p>
<p><em>private function timerHandler(event:TimerEvent):void<br />
{<br />
var isReady:Boolean = isContainerReady();<br />
if (isReady)<br />
{<br />
Timer(event.target).stop();<br />
setupCallbacks();<br />
}</em></p>
<p><em>}<br />
</em></p>
<p><span style="color: #808080;"><em><br />
private function callFlexApp(param1:int, param2:int):void<br />
{<br />
// this function is called from javascript</em></span></p>
<p><span style="color: #808080;"><em> }</em></span></p>
<p><em>}</em></p>
<p><em>}</em></p></blockquote>
<p>That&#8217;s the short description how to set up a communcation between JavaScript and Flex.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2009/03/07/flex-javascript-communication/" rel="bookmark" title="Flex Javascript communication">Flex Javascript communication </a></li>
<li><a href="/2009/10/29/passing-objects-with-externalinterface-from-js-to-flex/" rel="bookmark" title="Passing objects with ExternalInterface from JS to Flex">Passing objects with ExternalInterface from JS to Flex </a></li>
<li><a href="/2009/07/08/externalinterface-from-javascript-to-ie-firefox/" rel="bookmark" title="ExternalInterface from JavaScript to IE/Firefox">ExternalInterface from JavaScript to IE/Firefox </a></li>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2009/03/09/flex-javascript-communcation-example/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Flex Javascript communication</title>
		<link>/2009/03/07/flex-javascript-communication/</link>
		<comments>/2009/03/07/flex-javascript-communication/#comments</comments>
		<pubDate>Sat, 07 Mar 2009 09:15:05 +0000</pubDate>
		<dc:creator><![CDATA[stoimen]]></dc:creator>
				<category><![CDATA[featured]]></category>
		<category><![CDATA[flex 3]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[swfaddress]]></category>
		<category><![CDATA[timeout]]></category>
		<category><![CDATA[uri]]></category>

		<guid isPermaLink="false">/?p=303</guid>
		<description><![CDATA[Learn which way to make the communication between javascript and flex is the best for your solution.<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2009/03/09/flex-javascript-communcation-example/" rel="bookmark" title="Flex Javascript communcation example">Flex Javascript communcation example </a></li>
<li><a href="/2009/10/28/tips-and-tricks-in-externalinterface-communication/" rel="bookmark" title="Tips and tricks in ExternalInterface communication!">Tips and tricks in ExternalInterface communication! </a></li>
<li><a href="/2009/02/09/ie-externalinterface-communication-problem/" rel="bookmark" title="IE &#038; ExternalInterface communication problem">IE &#038; ExternalInterface communication problem </a></li>
<li><a href="/2009/10/29/passing-objects-with-externalinterface-from-js-to-flex/" rel="bookmark" title="Passing objects with ExternalInterface from JS to Flex">Passing objects with ExternalInterface from JS to Flex </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>Communication between JavaScript and Flex applications can be done in many ways. Using SWFAddress and communicate with the help of the uri or using ExternalInterface flash communication interface are the most used.</p>
<p>The disadvantages of using SWFAddress is that the communication is slow and it had to change the uri, which is not always something the developer needs. In general the the Flex application listens for uri changes, simply by setting a timeout for a listener with very short period of time, like 10 milliseconds, and if some change occurs get&#8217;s the uri, parses it and process the changes.</p>
<p>From the beginning the hard-coded listening of the uri change is not a good idea. Even for very short timeouts it become risky when the user can click and skip an important refresh inside the flex application.</p>
<p>I strongly recommend the use of the build in ExternalInterface. The communication via ExternalInterface can be done in both directions to JavaScript to Flex and vice versa, which is the main advantage is the lack of programmatically added listening processes. Here all it&#8217;s done by the interface and the response from the other side is guaranteed.</p>
<p>There are tricky parts, of course, but in general it&#8217;s a secure and reliable way to talk between these two technologies.</p>
<p>A sample of the process you can find <a title="flex to javascript communication with externalInterface" href="/2009/03/09/flex-javascript-communcation-example/" target="_self">here</a>.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2009/03/09/flex-javascript-communcation-example/" rel="bookmark" title="Flex Javascript communcation example">Flex Javascript communcation example </a></li>
<li><a href="/2009/10/28/tips-and-tricks-in-externalinterface-communication/" rel="bookmark" title="Tips and tricks in ExternalInterface communication!">Tips and tricks in ExternalInterface communication! </a></li>
<li><a href="/2009/02/09/ie-externalinterface-communication-problem/" rel="bookmark" title="IE &#038; ExternalInterface communication problem">IE &#038; ExternalInterface communication problem </a></li>
<li><a href="/2009/10/29/passing-objects-with-externalinterface-from-js-to-flex/" rel="bookmark" title="Passing objects with ExternalInterface from JS to Flex">Passing objects with ExternalInterface from JS to Flex </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2009/03/07/flex-javascript-communication/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
