<?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>beer planet &#187; xml</title> <atom:link href="http://beerpla.net/tag/xml/feed/" rel="self" type="application/rss+xml" /><link>http://beerpla.net</link> <description>where things have nothing to do with beer - tutorials, tips, how-tos, thoughts, hacks, and other techy nonsense</description> <lastBuildDate>Thu, 17 May 2012 22:50:53 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <atom:link rel='hub' href='http://beerpla.net/?pushpress=hub'/> <item><title>How To Dynamically Increase Memory Limits When Interfacing With WordPress Using XML-RPC (Windows Live Writer, Etc)</title><link>http://beerpla.net/2010/11/06/how-to-dynamically-increase-memory-limits-when-interfacing-with-wordpress-using-xml-rpc-windows-live-writer-etc/</link> <comments>http://beerpla.net/2010/11/06/how-to-dynamically-increase-memory-limits-when-interfacing-with-wordpress-using-xml-rpc-windows-live-writer-etc/#comments</comments> <pubDate>Sat, 06 Nov 2010 09:00:44 +0000</pubDate> <dc:creator>Artem Russakovskii</dc:creator> <category><![CDATA[Performance]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Tips]]></category> <category><![CDATA[Tutorials]]></category> <category><![CDATA[Wordpress]]></category> <category><![CDATA[apache]]></category> <category><![CDATA[error 500]]></category> <category><![CDATA[limit]]></category> <category><![CDATA[memory]]></category> <category><![CDATA[out of memory]]></category> <category><![CDATA[rpc]]></category> <category><![CDATA[server error]]></category> <category><![CDATA[web server]]></category> <category><![CDATA[Windows Live Writer]]></category> <category><![CDATA[WLW]]></category> <category><![CDATA[xml]]></category> <category><![CDATA[xml-rpc]]></category> <category><![CDATA[xmlrpc]]></category> <guid
isPermaLink="false">http://beerpla.net/2010/11/06/how-to-dynamically-increase-memory-limits-when-interfacing-with-wordpress-using-xml-rpc-windows-live-writer-etc/</guid> <description><![CDATA[<p>Today&#039;s snippet is tremendously helpful if you are using an XML-RPC WordPress interface to read and publish your articles and are running into <em><strong>500 Server Error</strong></em> issues due to running out of memory, manifesting themselves in something like this error message: <em><strong>&#34;Invalid Server Response &#8211; The response to the metaWeblog.newMediaObject method received from the weblog server was invalid&#34;</strong></em>.</p><p>For example, my regular PHP memory allocation is 32MB or so, but if I load up Windows Live Writer, my favorite publishing tool, and ask it to load 1000 of the latest blog posts, I will undoubtedly get a server error back.</p><p>One solution would be to increase the memory allocated to PHP to something higher, like 256MB, which is how ...<div
class=clear></div> <a
href="http://beerpla.net/2010/11/06/how-to-dynamically-increase-memory-limits-when-interfacing-with-wordpress-using-xml-rpc-windows-live-writer-etc/" class="read_more"><div
class=excerpt-end>Read the rest of this article &#187;</div></a></p>]]></description> <content:encoded><![CDATA[<p>Today&#039;s snippet is tremendously helpful if you are using an XML-RPC WordPress interface to read and publish your articles and are running into <em><strong>500 Server Error</strong></em> issues due to running out of memory, manifesting themselves in something like this error message: <em><strong>&quot;Invalid Server Response &#8211; The response to the metaWeblog.newMediaObject method received from the weblog server was invalid&quot;</strong></em>.</p><p>For example, my regular PHP memory allocation is 32MB or so, but if I load up Windows Live Writer, my favorite publishing tool, and ask it to load 1000 of the latest blog posts, I will undoubtedly get a server error back.</p><p>One solution would be to increase the memory allocated to PHP to something higher, like 256MB, which is how I used to get around the issue. I say &quot;get around&quot; because it&#039;s not a good solution &#8211; if someone finds a page that uses a lot of memory on your site, they could easily kill not only your web server but the whole machine due to swap death. Keeping a lower memory limit allows you to run your web server, such as Apache, with more children, thus serving more requests without getting overloaded.</p><p>So, I&#039;ve looked into the WordPress core and came up with what I think is a proper fix &#8211; dynamic memory limit tweaking when dealing with XML-RPC only. Here is the code &#8211; add it to your <em><strong>functions.php</strong></em> and you should be golden:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td
class="code"><pre>/**
* Dynamically increase allowed memory limit for XML-RPC only.
*
* @param array $methods
* @return array
*/
function my_xmlrpc_methods($methods) {
  ini_set('memory_limit', '256M');
  return $methods;
}
add_action('xmlrpc_methods', 'my_xmlrpc_methods');</pre></td></tr></table></div><p>The code is pretty self-explanatory: it hooks into a WordPress hook that fires only for XML-RPC requests and adjusts the memory limit on the fly. No more out of memory errors and I&#039;m able to load 1000 posts in Windows Live Writer without problems.</p><div
class="shr-bookmarks shr-bookmarks-expand"><ul
class="socials"><li
class="shr-twitter"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Dynamically+Increase+Memory+Limits+When+Interfacing+With+Wordpress+Using+XML-RPC+%28Windows+Live+Writer%2C+Etc%29&amp;link=http://beerpla.net/2010/11/06/how-to-dynamically-increase-memory-limits-when-interfacing-with-wordpress-using-xml-rpc-windows-live-writer-etc/&amp;notes=Today%27s%20snippet%20is%20tremendously%20helpful%20if%20you%20are%20using%20an%20XML-RPC%20Wordpress%20interface%20to%20read%20and%20publish%20your%20articles%20and%20are%20running%20into%20500%20Server%20Error%20issues%20due%20to%20running%20out%20of%20memory%2C%20manifesting%20themselves%20in%20something%20like%20this%20error%20message%3A%20%26quot%3BInvalid%20Server%20Response%20-%20The%20respon&amp;short_link=http://bit.ly/cOxNJ3&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%24%7Btitle%7D+-+%24%7Bshort_link%7D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li
class="shr-facebook"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Dynamically+Increase+Memory+Limits+When+Interfacing+With+Wordpress+Using+XML-RPC+%28Windows+Live+Writer%2C+Etc%29&amp;link=http://beerpla.net/2010/11/06/how-to-dynamically-increase-memory-limits-when-interfacing-with-wordpress-using-xml-rpc-windows-live-writer-etc/&amp;notes=Today%27s%20snippet%20is%20tremendously%20helpful%20if%20you%20are%20using%20an%20XML-RPC%20Wordpress%20interface%20to%20read%20and%20publish%20your%20articles%20and%20are%20running%20into%20500%20Server%20Error%20issues%20due%20to%20running%20out%20of%20memory%2C%20manifesting%20themselves%20in%20something%20like%20this%20error%20message%3A%20%26quot%3BInvalid%20Server%20Response%20-%20The%20respon&amp;short_link=http://bit.ly/cOxNJ3&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a></li><li
class="shr-googlebuzz"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Dynamically+Increase+Memory+Limits+When+Interfacing+With+Wordpress+Using+XML-RPC+%28Windows+Live+Writer%2C+Etc%29&amp;link=http://beerpla.net/2010/11/06/how-to-dynamically-increase-memory-limits-when-interfacing-with-wordpress-using-xml-rpc-windows-live-writer-etc/&amp;notes=Today%27s%20snippet%20is%20tremendously%20helpful%20if%20you%20are%20using%20an%20XML-RPC%20Wordpress%20interface%20to%20read%20and%20publish%20your%20articles%20and%20are%20running%20into%20500%20Server%20Error%20issues%20due%20to%20running%20out%20of%20memory%2C%20manifesting%20themselves%20in%20something%20like%20this%20error%20message%3A%20%26quot%3BInvalid%20Server%20Response%20-%20The%20respon&amp;short_link=http://bit.ly/cOxNJ3&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=257&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a></li><li
class="shr-reddit"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Dynamically+Increase+Memory+Limits+When+Interfacing+With+Wordpress+Using+XML-RPC+%28Windows+Live+Writer%2C+Etc%29&amp;link=http://beerpla.net/2010/11/06/how-to-dynamically-increase-memory-limits-when-interfacing-with-wordpress-using-xml-rpc-windows-live-writer-etc/&amp;notes=Today%27s%20snippet%20is%20tremendously%20helpful%20if%20you%20are%20using%20an%20XML-RPC%20Wordpress%20interface%20to%20read%20and%20publish%20your%20articles%20and%20are%20running%20into%20500%20Server%20Error%20issues%20due%20to%20running%20out%20of%20memory%2C%20manifesting%20themselves%20in%20something%20like%20this%20error%20message%3A%20%26quot%3BInvalid%20Server%20Response%20-%20The%20respon&amp;short_link=http://bit.ly/cOxNJ3&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a></li><li
class="shr-hackernews"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Dynamically+Increase+Memory+Limits+When+Interfacing+With+Wordpress+Using+XML-RPC+%28Windows+Live+Writer%2C+Etc%29&amp;link=http://beerpla.net/2010/11/06/how-to-dynamically-increase-memory-limits-when-interfacing-with-wordpress-using-xml-rpc-windows-live-writer-etc/&amp;notes=Today%27s%20snippet%20is%20tremendously%20helpful%20if%20you%20are%20using%20an%20XML-RPC%20Wordpress%20interface%20to%20read%20and%20publish%20your%20articles%20and%20are%20running%20into%20500%20Server%20Error%20issues%20due%20to%20running%20out%20of%20memory%2C%20manifesting%20themselves%20in%20something%20like%20this%20error%20message%3A%20%26quot%3BInvalid%20Server%20Response%20-%20The%20respon&amp;short_link=http://bit.ly/cOxNJ3&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=202&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a></li><li
class="shr-delicious"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Dynamically+Increase+Memory+Limits+When+Interfacing+With+Wordpress+Using+XML-RPC+%28Windows+Live+Writer%2C+Etc%29&amp;link=http://beerpla.net/2010/11/06/how-to-dynamically-increase-memory-limits-when-interfacing-with-wordpress-using-xml-rpc-windows-live-writer-etc/&amp;notes=Today%27s%20snippet%20is%20tremendously%20helpful%20if%20you%20are%20using%20an%20XML-RPC%20Wordpress%20interface%20to%20read%20and%20publish%20your%20articles%20and%20are%20running%20into%20500%20Server%20Error%20issues%20due%20to%20running%20out%20of%20memory%2C%20manifesting%20themselves%20in%20something%20like%20this%20error%20message%3A%20%26quot%3BInvalid%20Server%20Response%20-%20The%20respon&amp;short_link=http://bit.ly/cOxNJ3&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=2&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li
class="shr-stumbleupon"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Dynamically+Increase+Memory+Limits+When+Interfacing+With+Wordpress+Using+XML-RPC+%28Windows+Live+Writer%2C+Etc%29&amp;link=http://beerpla.net/2010/11/06/how-to-dynamically-increase-memory-limits-when-interfacing-with-wordpress-using-xml-rpc-windows-live-writer-etc/&amp;notes=Today%27s%20snippet%20is%20tremendously%20helpful%20if%20you%20are%20using%20an%20XML-RPC%20Wordpress%20interface%20to%20read%20and%20publish%20your%20articles%20and%20are%20running%20into%20500%20Server%20Error%20issues%20due%20to%20running%20out%20of%20memory%2C%20manifesting%20themselves%20in%20something%20like%20this%20error%20message%3A%20%26quot%3BInvalid%20Server%20Response%20-%20The%20respon&amp;short_link=http://bit.ly/cOxNJ3&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li
class="shr-mail"> <a
href="http://www.shareaholic.com/api/share/?title=How%20To%20Dynamically%20Increase%20Memory%20Limits%20When%20Interfacing%20With%20Wordpress%20Using%20XML-RPC%20%28Windows%20Live%20Writer%2C%20Etc%29&amp;link=http://beerpla.net/2010/11/06/how-to-dynamically-increase-memory-limits-when-interfacing-with-wordpress-using-xml-rpc-windows-live-writer-etc/&amp;notes=Today%27s%20snippet%20is%20tremendously%20helpful%20if%20you%20are%20using%20an%20XML-RPC%20Wordpress%20interface%20to%20read%20and%20publish%20your%20articles%20and%20are%20running%20into%20500%20Server%20Error%20issues%20due%20to%20running%20out%20of%20memory%2C%20manifesting%20themselves%20in%20something%20like%20this%20error%20message%3A%20%26quot%3BInvalid%20Server%20Response%20-%20The%20respon&amp;short_link=http://bit.ly/cOxNJ3&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=201&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a></li></ul><div
style="clear: both;"></div></div> Similar Posts:<ul><li><a
href="http://beerpla.net/2012/04/13/how-to-fix-incomplete-wordpress-wxr-exports/" rel="bookmark" title="April 13, 2012">How To Fix Incomplete WordPress (WXR) Exports</a></li><li><a
href="http://beerpla.net/2011/11/16/how-to-disableblock-external-http-requests-in-wordpress/" rel="bookmark" title="November 16, 2011">How To: Disable/Block External HTTP Requests In WordPress</a></li><li><a
href="http://beerpla.net/2010/01/15/follow-up-to-loading-css-and-js-conditionally/" rel="bookmark" title="January 15, 2010">Follow-up To Loading CSS And JS Conditionally</a></li><li><a
href="http://beerpla.net/2010/01/13/wordpress-plugin-development-how-to-include-css-and-javascript-conditionally-and-only-when-needed-by-the-posts/" rel="bookmark" title="January 13, 2010">[WordPress Plugin Development] How To Include CSS and JavaScript Conditionally And Only When Needed By The Posts</a></li><li><a
href="http://beerpla.net/2010/10/15/how-to-add-shortcode-support-to-wordpress-comments-and-sidebars/" rel="bookmark" title="October 15, 2010">How To Add Shortcode Support To WordPress Comments And Sidebar Widgets</a></li></ul><p><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbeerpla.net%2F2010%2F11%2F06%2Fhow-to-dynamically-increase-memory-limits-when-interfacing-with-wordpress-using-xml-rpc-windows-live-writer-etc%2F&amp;title=How%20To%20Dynamically%20Increase%20Memory%20Limits%20When%20Interfacing%20With%20WordPress%20Using%20XML-RPC%20%28Windows%20Live%20Writer%2C%20Etc%29" id="wpa2a_2"><img
src="http://beerpla.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://beerpla.net/2010/11/06/how-to-dynamically-increase-memory-limits-when-interfacing-with-wordpress-using-xml-rpc-windows-live-writer-etc/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>[Android] Auto Formatting Android XML Files With Eclipse</title><link>http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/</link> <comments>http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/#comments</comments> <pubDate>Thu, 05 Nov 2009 02:44:54 +0000</pubDate> <dc:creator>Artem Russakovskii</dc:creator> <category><![CDATA[Android]]></category> <category><![CDATA[Eclipse]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Tips]]></category> <category><![CDATA[Tutorials]]></category> <category><![CDATA[auto format]]></category> <category><![CDATA[autoformat]]></category> <category><![CDATA[automatic]]></category> <category><![CDATA[clean up]]></category> <category><![CDATA[cleanup]]></category> <category><![CDATA[format]]></category> <category><![CDATA[indentation]]></category> <category><![CDATA[tag]]></category> <category><![CDATA[xml]]></category> <guid
isPermaLink="false">http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/</guid> <description><![CDATA[<p><img
style="margin: 0px 10px 10px 0px; display: inline" title="image" alt="image" align="left" src="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_thumb.png" width="150" height="109" /> In this article I will describe the problem I&#039;ve had with Eclipse&#039;s handling of XML file formatting as well as the best way to fix it.</p><p>&#160;</p><p>I use Eclipse to do my Android development for a few reasons:</p><ul><li>it&#039;s the only IDE fully supported by the Android dev team</li><li>it has a visual Layout/Resources builder that transforms XML files into corresponding visual representations</li><li>it&#039;s free and open source</li><li>I&#039;ve been using Eclipse for many years and am very familiar with it</li></ul><p><div
class="note"><div
class="noteclassic">In order to use the visual features in Eclipse when developing for Android, you need to install <a
href="http://developer.android.com/sdk/eclipse-adt.html" rel="nofollow">the ADT plugin</a> provided by Google</div></div></p><h2>The Problem</h2><p>However, one thing about Eclipse Android development has bothered me for a while ...<div
class=clear></div> <a
href="http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/" class="read_more"><div
class=excerpt-end>Read the rest of this article &#187;</div></a></p>]]></description> <content:encoded><![CDATA[<p><img
style="margin: 0px 10px 10px 0px; display: inline" title="image" alt="image" align="left" src="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_thumb.png" width="150" height="109" /> In this article I will describe the problem I&#039;ve had with Eclipse&#039;s handling of XML file formatting as well as the best way to fix it.</p><p>&#160;</p><p>I use Eclipse to do my Android development for a few reasons:</p><ul><li>it&#039;s the only IDE fully supported by the Android dev team</li><li>it has a visual Layout/Resources builder that transforms XML files into corresponding visual representations</li><li>it&#039;s free and open source</li><li>I&#039;ve been using Eclipse for many years and am very familiar with it</li></ul><p><div
class="note"><div
class="noteclassic">In order to use the visual features in Eclipse when developing for Android, you need to install <a
href="http://developer.android.com/sdk/eclipse-adt.html" rel="nofollow">the ADT plugin</a> provided by Google</div></div></p><h2>The Problem</h2><p>However, one thing about Eclipse Android development has bothered me for a while &#8211; and that is XML formatting by the visual tools. See, if you open an XML file in Eclipse and use the Layout/Resources tab (which functions as either a visual UI builder or a visual frontend to resource management), Eclipse creates the XML representation of what you&#039;re building and dumps it into the file you&#039;re editing. The problem is, this XML is not formatted in any way &#8211; Eclipse just writes it in a single line, which looks absolutely horrible and is essentially unusable.</p><p>For example, I had this beautifully formatted XML file with a sample Android menu. After using the Layout tab to add another item, I ended up with an single ugly unindented line for it.</p><p><a
href="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_3.png" class="lightview" rel="gallery['1215']" title="image"><img
style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_thumb_3.png" width="700" height="189" /></a></p><h2>The Solution</h2><p>Here&#039;s how to solve this in an almost fully automated fashion, using formatting rules that I think result in the most readable file. There is no need for external tools &#8211; Eclipse provides everything needed.</p><ul><li>open up Window-&gt;Preferences-&gt;XML-&gt;XML Files-&gt;Editor <br
/><a
href="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_4.png" class="lightview" rel="gallery['1215']" title="image"><img
style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_thumb_4.png" width="636" height="667" /></a></li><li>check the &quot;Split multiple attributes each on a new line&quot; and adjust other options according to your liking (such as Indent using spaces and Indentation size)</li><li>press OK to save the options</li><li>all you have to do now is press Ctrl-Shift-F or select Source-&gt;Format</li></ul><p>Let&#039;s see what this does to the XML I showed above:</p><p><a
href="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_5.png" class="lightview" rel="gallery['1215']" title="image"><img
style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_thumb_5.png" width="573" height="333" /></a> It&#039;s a beauty, isn&#039;t it? Eclipse&#039;s Auto Format is one of its best features (yes, you can apply it to your Android Java code too as well as pretty much any other document format).</p><h2>Bonus &#8211; XML Cleanup</h2><p>As an added bonus, Eclipse also offers a Cleanup XML option, which can do the following:</p><ul><li>compress empty element tags</li><li>insert required attributes</li><li>insert missing tags</li><li>quote attribute values</li><li>format source (as above)</li><li>convert line delimiters to Windows, UNIX, or Mac</li></ul><p>You can access the Cleanup option via Source-&gt;Cleanup</p><p><a
href="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_6.png" class="lightview" rel="gallery['1215']" title="image"><img
style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_thumb_6.png" width="225" height="247" /></a> Running Cleanup on my already pretty clean XML file turned the last &lt;item&gt; into this:</p><p><a
href="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_7.png" class="lightview" rel="gallery['1215']" title="image"><img
style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_thumb_7.png" width="554" height="104" /></a> The first option compressed the &lt;item&gt;&lt;/item&gt; declaration to simply &lt;item /&gt;. Neat, isn&#039;t it?</p><h2>Final Words</h2><p><strong>+</strong> Clean is good.</p><p><strong>+</strong> Uniform is good.</p><p><strong>+</strong> Use Ctrl-Shift-F and make it a habit.</p><p><strong>+</strong> Create a keyboard shortcut to the Cleanup function by going to Window-&gt;Preferences-&gt;General-&gt;Keys and use it instead of Ctrl-Shift-F (since it already formats as part of the Cleanup).</p><p><strong>?</strong> I&#039;d like to know if there is a way to apply auto formatting upon save, automatically. Do you?</p><div
class="shr-bookmarks shr-bookmarks-expand"><ul
class="socials"><li
class="shr-twitter"> <a
href="http://www.shareaholic.com/api/share/?title=%5BAndroid%5D+Auto+Formatting+Android+XML+Files+With+Eclipse&amp;link=http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/&amp;notes=%20In%20this%20article%20I%20will%20describe%20the%20problem%20I%27ve%20had%20with%20Eclipse%27s%20handling%20of%20XML%20file%20formatting%20as%20well%20as%20the%20best%20way%20to%20fix%20it.%20%20%26%23160%3B%20%20I%20use%20Eclipse%20to%20do%20my%20Android%20development%20for%20a%20few%20reasons%3A%20%20%20%20%20it%27s%20the%20only%20IDE%20fully%20supported%20by%20the%20Android%20dev%20team%20%20%20%20%20it%20has%20a%20visual%20Layout%2FReso&amp;short_link=http://bit.ly/cNm6Ld&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%24%7Btitle%7D+-+%24%7Bshort_link%7D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li
class="shr-facebook"> <a
href="http://www.shareaholic.com/api/share/?title=%5BAndroid%5D+Auto+Formatting+Android+XML+Files+With+Eclipse&amp;link=http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/&amp;notes=%20In%20this%20article%20I%20will%20describe%20the%20problem%20I%27ve%20had%20with%20Eclipse%27s%20handling%20of%20XML%20file%20formatting%20as%20well%20as%20the%20best%20way%20to%20fix%20it.%20%20%26%23160%3B%20%20I%20use%20Eclipse%20to%20do%20my%20Android%20development%20for%20a%20few%20reasons%3A%20%20%20%20%20it%27s%20the%20only%20IDE%20fully%20supported%20by%20the%20Android%20dev%20team%20%20%20%20%20it%20has%20a%20visual%20Layout%2FReso&amp;short_link=http://bit.ly/cNm6Ld&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a></li><li
class="shr-googlebuzz"> <a
href="http://www.shareaholic.com/api/share/?title=%5BAndroid%5D+Auto+Formatting+Android+XML+Files+With+Eclipse&amp;link=http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/&amp;notes=%20In%20this%20article%20I%20will%20describe%20the%20problem%20I%27ve%20had%20with%20Eclipse%27s%20handling%20of%20XML%20file%20formatting%20as%20well%20as%20the%20best%20way%20to%20fix%20it.%20%20%26%23160%3B%20%20I%20use%20Eclipse%20to%20do%20my%20Android%20development%20for%20a%20few%20reasons%3A%20%20%20%20%20it%27s%20the%20only%20IDE%20fully%20supported%20by%20the%20Android%20dev%20team%20%20%20%20%20it%20has%20a%20visual%20Layout%2FReso&amp;short_link=http://bit.ly/cNm6Ld&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=257&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a></li><li
class="shr-reddit"> <a
href="http://www.shareaholic.com/api/share/?title=%5BAndroid%5D+Auto+Formatting+Android+XML+Files+With+Eclipse&amp;link=http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/&amp;notes=%20In%20this%20article%20I%20will%20describe%20the%20problem%20I%27ve%20had%20with%20Eclipse%27s%20handling%20of%20XML%20file%20formatting%20as%20well%20as%20the%20best%20way%20to%20fix%20it.%20%20%26%23160%3B%20%20I%20use%20Eclipse%20to%20do%20my%20Android%20development%20for%20a%20few%20reasons%3A%20%20%20%20%20it%27s%20the%20only%20IDE%20fully%20supported%20by%20the%20Android%20dev%20team%20%20%20%20%20it%20has%20a%20visual%20Layout%2FReso&amp;short_link=http://bit.ly/cNm6Ld&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a></li><li
class="shr-hackernews"> <a
href="http://www.shareaholic.com/api/share/?title=%5BAndroid%5D+Auto+Formatting+Android+XML+Files+With+Eclipse&amp;link=http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/&amp;notes=%20In%20this%20article%20I%20will%20describe%20the%20problem%20I%27ve%20had%20with%20Eclipse%27s%20handling%20of%20XML%20file%20formatting%20as%20well%20as%20the%20best%20way%20to%20fix%20it.%20%20%26%23160%3B%20%20I%20use%20Eclipse%20to%20do%20my%20Android%20development%20for%20a%20few%20reasons%3A%20%20%20%20%20it%27s%20the%20only%20IDE%20fully%20supported%20by%20the%20Android%20dev%20team%20%20%20%20%20it%20has%20a%20visual%20Layout%2FReso&amp;short_link=http://bit.ly/cNm6Ld&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=202&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a></li><li
class="shr-delicious"> <a
href="http://www.shareaholic.com/api/share/?title=%5BAndroid%5D+Auto+Formatting+Android+XML+Files+With+Eclipse&amp;link=http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/&amp;notes=%20In%20this%20article%20I%20will%20describe%20the%20problem%20I%27ve%20had%20with%20Eclipse%27s%20handling%20of%20XML%20file%20formatting%20as%20well%20as%20the%20best%20way%20to%20fix%20it.%20%20%26%23160%3B%20%20I%20use%20Eclipse%20to%20do%20my%20Android%20development%20for%20a%20few%20reasons%3A%20%20%20%20%20it%27s%20the%20only%20IDE%20fully%20supported%20by%20the%20Android%20dev%20team%20%20%20%20%20it%20has%20a%20visual%20Layout%2FReso&amp;short_link=http://bit.ly/cNm6Ld&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=2&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li
class="shr-stumbleupon"> <a
href="http://www.shareaholic.com/api/share/?title=%5BAndroid%5D+Auto+Formatting+Android+XML+Files+With+Eclipse&amp;link=http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/&amp;notes=%20In%20this%20article%20I%20will%20describe%20the%20problem%20I%27ve%20had%20with%20Eclipse%27s%20handling%20of%20XML%20file%20formatting%20as%20well%20as%20the%20best%20way%20to%20fix%20it.%20%20%26%23160%3B%20%20I%20use%20Eclipse%20to%20do%20my%20Android%20development%20for%20a%20few%20reasons%3A%20%20%20%20%20it%27s%20the%20only%20IDE%20fully%20supported%20by%20the%20Android%20dev%20team%20%20%20%20%20it%20has%20a%20visual%20Layout%2FReso&amp;short_link=http://bit.ly/cNm6Ld&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li
class="shr-mail"> <a
href="http://www.shareaholic.com/api/share/?title=%5BAndroid%5D%20Auto%20Formatting%20Android%20XML%20Files%20With%20Eclipse&amp;link=http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/&amp;notes=%20In%20this%20article%20I%20will%20describe%20the%20problem%20I%27ve%20had%20with%20Eclipse%27s%20handling%20of%20XML%20file%20formatting%20as%20well%20as%20the%20best%20way%20to%20fix%20it.%20%20%26%23160%3B%20%20I%20use%20Eclipse%20to%20do%20my%20Android%20development%20for%20a%20few%20reasons%3A%20%20%20%20%20it%27s%20the%20only%20IDE%20fully%20supported%20by%20the%20Android%20dev%20team%20%20%20%20%20it%20has%20a%20visual%20Layout%2FReso&amp;short_link=http://bit.ly/cNm6Ld&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=201&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a></li></ul><div
style="clear: both;"></div></div> Similar Posts:<ul><li><a
href="http://beerpla.net/2008/04/09/some-useful-vim-commands-my-vim-cheatsheet/" rel="bookmark" title="April 9, 2008">Some Useful vim Commands &#8211; My vim Cheatsheet</a></li><li><a
href="http://beerpla.net/2009/10/15/installing-the-android-plugin-for-eclipse/" rel="bookmark" title="October 15, 2009">Installing The Android Plugin For Eclipse</a></li><li><a
href="http://beerpla.net/2010/09/29/how-to-update-eclipse-from-galileo-3-5-to-helios-3-6-in-place-without-reinstalling/" rel="bookmark" title="September 29, 2010">How To Update Eclipse From Galileo (3.5) To Helios (3.6) In-Place Without Reinstalling</a></li><li><a
href="http://beerpla.net/2010/01/18/wordpress-developers-how-do-you-make-a-living-poll-discussion/" rel="bookmark" title="January 18, 2010">WordPress Developers &#8211; How Do You Make A Living [Poll + Discussion]?</a></li><li><a
href="http://beerpla.net/2008/12/22/mastering-the-linux-shell-bash-shortcuts-explained/" rel="bookmark" title="December 22, 2008">Mastering The Linux Shell &#8211; Bash Shortcuts Explained (Now With Cheat Sheets)</a></li></ul><p><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbeerpla.net%2F2009%2F11%2F04%2Fandroid-auto-formatting-android-xml-files-with-eclipse%2F&amp;title=%5BAndroid%5D%20Auto%20Formatting%20Android%20XML%20Files%20With%20Eclipse" id="wpa2a_4"><img
src="http://beerpla.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/feed/</wfw:commentRss> <slash:comments>7</slash:comments> </item> <item><title>How To Make Your Site Lightning Fast* By Compressing (deflate/gzip) Your HTML, Javascript, CSS, XML, etc In Apache</title><link>http://beerpla.net/2009/06/09/how-to-make-your-site-lightning-fast-by-compressing-deflategzip-your-html-javascript-css-xml-etc-in-apache/</link> <comments>http://beerpla.net/2009/06/09/how-to-make-your-site-lightning-fast-by-compressing-deflategzip-your-html-javascript-css-xml-etc-in-apache/#comments</comments> <pubDate>Tue, 09 Jun 2009 17:02:00 +0000</pubDate> <dc:creator>Artem Russakovskii</dc:creator> <category><![CDATA[CSS]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Technology]]></category> <category><![CDATA[Tutorials]]></category> <category><![CDATA[Wordpress]]></category> <category><![CDATA[apache]]></category> <category><![CDATA[compress]]></category> <category><![CDATA[compression]]></category> <category><![CDATA[deflate]]></category> <category><![CDATA[fast]]></category> <category><![CDATA[faster]]></category> <category><![CDATA[gzip]]></category> <category><![CDATA[html]]></category> <category><![CDATA[js]]></category> <category><![CDATA[minify]]></category> <category><![CDATA[mod_deflate]]></category> <category><![CDATA[smaller]]></category> <category><![CDATA[text]]></category> <category><![CDATA[xml]]></category> <guid
isPermaLink="false">http://beerpla.net/?p=982</guid> <description><![CDATA[<p><span
style="font-size: xx-small">* Lightning Fast is a blatant exaggeration. Got you to look though, didn&#039;t it?</span></p><h2>Introduction</h2><p>Whether you are a web developer or a self-hosting business owner, the only excuse for not activating compression capabilities of your web server can be that you didn&#039;t know about it. And now that you are reading this, there is no excuse left at all.</p><p>Here is how big a single page of this blog was before compression was enabled on CSS and Javascript files (computed by <a
href="http://developer.yahoo.com/yslow/" rel="nofollow">YSlow</a>):</p><p><a
href="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_3.png" class="lightview" rel="gallery['982']" title="image"><img
style="display: inline; margin-left: 0px; margin-right: 0px" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_thumb_3.png" width="132" height="24" /></a></p><p>And here it is after compression:</p><p><a
href="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_4.png" class="lightview" rel="gallery['982']" title="image"><img
style="display: inline; margin-left: 0px; margin-right: 0px" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_thumb_4.png" width="136" height="28" /></a></p><p>As you see, the difference is quite substantial &#8211; almost 30% savings.</p><p>Compressing your HTML, XML, Javascript, CSS, etc pages will mean less data transferred between the server and the ...<div
class=clear></div> <a
href="http://beerpla.net/2009/06/09/how-to-make-your-site-lightning-fast-by-compressing-deflategzip-your-html-javascript-css-xml-etc-in-apache/" class="read_more"><div
class=excerpt-end>Read the rest of this article &#187;</div></a></p>]]></description> <content:encoded><![CDATA[<p><span
style="font-size: xx-small">* Lightning Fast is a blatant exaggeration. Got you to look though, didn&#039;t it?</span></p><h2>Introduction</h2><p>Whether you are a web developer or a self-hosting business owner, the only excuse for not activating compression capabilities of your web server can be that you didn&#039;t know about it. And now that you are reading this, there is no excuse left at all.</p><p>Here is how big a single page of this blog was before compression was enabled on CSS and Javascript files (computed by <a
href="http://developer.yahoo.com/yslow/" rel="nofollow">YSlow</a>):</p><p><a
href="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_3.png" class="lightview" rel="gallery['982']" title="image"><img
style="display: inline; margin-left: 0px; margin-right: 0px" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_thumb_3.png" width="132" height="24" /></a></p><p>And here it is after compression:</p><p><a
href="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_4.png" class="lightview" rel="gallery['982']" title="image"><img
style="display: inline; margin-left: 0px; margin-right: 0px" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_thumb_4.png" width="136" height="28" /></a></p><p>As you see, the difference is quite substantial &#8211; almost 30% savings.</p><p>Compressing your HTML, XML, Javascript, CSS, etc pages will mean less data transferred between the server and the client which:</p><ul><li>reduces the bandwidth usage.</li><li>provides faster page rendering which in turn leads to less user frustration, higher conversion rates, lower bounce rate, etc etc etc.</li></ul><p>Compression is especially important for users with slow connections as every kilobyte of your code is that much more painful to them.</p><p>Compression can be very effective &#8211; you can easily shrink your text, code (HTML, XML, Javascript, CSS, etc) to 10% of the original size (of course, your mileage may vary). 100KB page that needs only 10KB to transfer? Sign me up!</p><p>So, before I talk about the solution, let me describe what exactly happens when compression is turned on and how it affects older browsers that don&#039;t support it.</p><p><div
class="note"><div
class="notetip"></p><p><a
href="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_17.png" class="lightview" rel="gallery['982']" title="image"><img
style="margin: 0px auto 10px; display: block; float: none" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_thumb_17.png" width="292" height="177" /></a> <strong>Are you using jQuery?</strong></p><p>Did you know that a minified jQuery file is <strong>55KB</strong>? In order to achieve the advertised <strong>19KB</strong>, you would still need to compress the .js file using the methods listed here.</div></div></p><h2>Compression Mechanism Explained</h2><p>In order for compression to work in the first place, the web server (Apache in my example) needs to support it. This is achieved by enabling one of Apache modules called mod_deflate. The server will then be able to compress the data to the DEFLATE standard using either the zlib (also known as deflate) or gzip implementations. Yeah, DEFLATE is both the standard the one of its implementations, for those confused. I know I was. This is best described in <a
href="http://en.wikipedia.org/wiki/Gzip#Other_uses" rel="nofollow">this Wikipedia article</a>.</p><p>The following mechanism is used:</p><ul><li>the server with a compression extension enabled is able to serve either compressed (smaller) or uncompressed (larger) pages, depending on what the client supports.</li><li>the client (that is, your browser) sends a special header called &quot;Accept-Encoding&quot; listing the DEFLATE implementations it&#039;s capable of decompressing. For example &quot;gzip,deflate&quot;.</li><li>the server picks the best compression supported by the client (if any), compresses the files, and sends them over to the client.</li><li>the client receives the compressed files and decompresses them.</li></ul><p><div
class="note"><div
class="notetip"><strong>Are you using a load blancer?</strong></p><p>If you are using a load balancer, it may already be configured to compress pages that pass through it. In that case, there is no need to separately configure compression on your web servers. In fact, it should be off to save CPU.</div></div></p><h2>Are Your Pages Already Compressed? Test Them!</h2><p>If you are not sure whether you are already serving compressed pages or not, test them! My favorite way is by using <a
href="http://www.charlesproxy.com/" rel="nofollow">Charles HTTP Debugger</a>. Another option is by downloading <a
href="http://getfirebug.com/" rel="nofollow">Firebug</a> for Firefox and installing Yahoo&#039;s <a
href="http://developer.yahoo.com/yslow/" rel="nofollow">YSlow</a> or Google&#039;s <a
href="http://code.google.com/speed/page-speed/" rel="nofollow">Page Speed</a>. Just look at the response headers to see if compression is on (look for the Content-Encoding header). Here are some before and after examples:</p><h3>Theme CSS</h3><p><a
href="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_5.png" class="lightview" rel="gallery['982']" title="image"><img
style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_thumb_5.png" width="427" height="36" /></a></p><p>Before:</p><p><a
href="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_6.png" class="lightview" rel="gallery['982']" title="image"><img
style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_thumb_6.png" width="266" height="136" /></a></p><p>After:</p><p><a
href="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_7.png" class="lightview" rel="gallery['982']" title="image"><img
style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_thumb_7.png" width="267" height="161" /></a></p><h3>jQuery</h3><p><a
href="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_8.png" class="lightview" rel="gallery['982']" title="image"><img
style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_thumb_8.png" width="469" height="39" /></a></p><p>Before:</p><p><a
href="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_9.png" class="lightview" rel="gallery['982']" title="image"><img
style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_thumb_9.png" width="263" height="132" /></a></p><p>After:</p><p><a
href="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_10.png" class="lightview" rel="gallery['982']" title="image"><img
style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_thumb_10.png" width="273" height="168" /></a></p><h2>Solution</h2><p>Create a .htaccess file in the top directory of your site with the following contents:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td
class="code"><pre># DEFLATE by type - html, text, css, xml
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml
&nbsp;
# DEFLATE by type - javascript
AddOutputFilterByType DEFLATE application/x-javascript application/javascript text/javascript text/x-js text/x-javascript
&nbsp;
# DEFLATE by extension
AddOutputFilter DEFLATE js css htm html xml</pre></td></tr></table></div><p>Alternatively, you could put these lines into your Apache config within the Directory directive.</p><p>The <a
href="http://httpd.apache.org/docs/2.2/mod/core.html#addoutputfilterbytype" rel="nofollow">AddOutputFilterByType</a> directive adds DEFLATE filters to certain MIME types. I tried to assemble some of the common ones but feel free to add more, as each server may be configured differently and give out MIME types different from mine.</p><p><div
class="note"><div
class="notetip">You can find your own server&#039;s MIME type definitions in the file that the TypesConfig directive is pointing to (mine is /etc/mime.types).</div></div></p><p>The <a
href="http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addoutputfilter" rel="nofollow">AddOutputFilter</a> directive binds the DEFLATE filter to specific file extensions, just in case they are not served with a proper MIME type. Feel free to add to this list as well.</p><h2>Caveats</h2><p>1. In order to use this whole compression/deflate/gzip business, your Apache server must first have mod_deflate enabled. Without it, you will get the HTTP 500 error (Internal Server error). You can check which mods you already have enabled by checking with the output of phpinfo() function.</p><p><a
href="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_13.png" class="lightview" rel="gallery['982']" title="image"><img
style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_thumb_13.png" width="606" height="97" /></a></p><p>In order to enable mod_deflate, uncomment the line with &quot;deflate_module&quot; in your Apache config file. The location of this config file is highly dependant on your system. Some examples include</p><ul><li>/etc/apache2/httpd.conf</li><li>/etc/httpd/conf/httpd.conf</li><li>c:\wamp\bin\apache\Apache2.2.11\conf\httpd.conf</li><li>some other place where your system stores Apache config files (read the special note below for OpenSUSE).</li></ul><p>Here&#039;s what you should have:</p><div
class="wp_syntax"><div
class="code"><pre>LoadModule deflate_module modules/mod_deflate.so</pre></div></div><p>On OpenSUSE, you actually enable modules a bit differently. Go to /etc/sysconfig/apache2 and look for APACHE_MODULES=. Then add &quot;deflate&quot; to the list, if it&#039;s not already there.</p><p>Now, restart Apache and check the output of phpinfo() again.</p><p>2. Adding AddOutputFilter and AddOutputFilterByType to .htaccess requires such overrides to be authorized by the main Apache configuration for that directory, otherwise it will return error 500 as well. The option you are looking for is called &quot;AllowOverride&quot; and mine was set to &quot;AllowOverride AuthConfig&quot; which wasn&#039;t enough. Changing it to</p><div
class="wp_syntax"><div
class="code"><pre>AllowOverride AuthConfig FileInfo</pre></div></div><p>or just</p><div
class="wp_syntax"><div
class="code"><pre>AllowOverride All</pre></div></div><p>fixes the problem. You can find more info about AllowOverride <a
href="http://httpd.apache.org/docs/1.3/mod/core.html#allowoverride" rel="nofollow">here</a>.</p><p>3. In WordPress, if you are using Google Gears (<a
href="http://en.blog.wordpress.com/2008/07/02/gears/" rel="nofollow">Turbo mode</a>) for caching some core WordPress files, they will not show up compressed. That is because they&#039;re not served by the remote server but rather reside locally (think of it as permanent cache). I was very confused at first when I didn&#039;t see jQuery.js in the HTTP log and YSlow reported it uncompressed.</p><h2>Are you a WordPress user?</h2><p>If you are a WordPress user, don&#039;t assume WordPress is going to automatically compress your pages. In fact, as you install more and more plugins, the payload becomes larger and larger with those additional CSS and Javascript files.</p><p>You owe it to yourself and to your users to immediately enable compression on your blog.</p><p>Here is what happened after I enabled compression on this blog.</p><p>Before:</p><p><a
href="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_11.png" class="lightview" rel="gallery['982']" title="image"><img
style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_thumb_11.png" width="676" height="418" /></a></p><p>After:</p><p><a
href="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_12.png" class="lightview" rel="gallery['982']" title="image"><img
style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_thumb_12.png" width="440" height="115" /></a></p><h2>Bonus &#8211; WP Minify</h2><p>For even better results, I suggest you have a look at my good friend and talented WordPress master Thaya&#039;s plugin called <a
href="http://omninoggin.com/wordpress-plugins/wp-minify-wordpress-plugin/">WP Minify</a>. It preprocesses and aggregates all or most of your CSS and Javascript into just 2 files, thus saving on the number of HTTP requests. It also minifies content to achieve smaller size.</p><p>My blog before WP Minify:</p><p><a
href="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_14.png" class="lightview" rel="gallery['982']" title="image"><img
style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_thumb_14.png" width="413" height="62" /></a></p><p>After WP Minify:</p><p><a
href="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_15.png" class="lightview" rel="gallery['982']" title="image"><img
style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/HowToCompressdeflategzipYourPagesJavascr_11A9F/image_thumb_15.png" width="408" height="59" /></a></p><p>&#160;</p><p>That&#039;s all folks. Let me know if something was unclear and I&#039;ll be glad to clarify it.</p><p>A few references that pointed me in the right direction and allowed me to provide a more complete solution:</p><ul><li><a
title="http://brightscape.net/compress-jquery-even-further/" href="http://brightscape.net/compress-jquery-even-further/">http://brightscape.net/compress-jquery-even-further/</a></li><li><a
title="http://brightscape.net/compress-your-web-pages-with-mod_deflate/" href="http://brightscape.net/compress-your-web-pages-with-mod_deflate/">http://brightscape.net/compress-your-web-pages-with-mod_deflate/</a></li></ul><div
class="shr-bookmarks shr-bookmarks-expand"><ul
class="socials"><li
class="shr-twitter"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Make+Your+Site+Lightning+Fast%2A+By+Compressing+%28deflate%2Fgzip%29+Your+HTML%2C+Javascript%2C+CSS%2C+XML%2C+etc+In+Apache&amp;link=http://beerpla.net/2009/06/09/how-to-make-your-site-lightning-fast-by-compressing-deflategzip-your-html-javascript-css-xml-etc-in-apache/&amp;notes=%2A%20Lightning%20Fast%20is%20a%20blatant%20exaggeration.%20Got%20you%20to%20look%20though%2C%20didn%27t%20it%3F%20%20Introduction%20%20Whether%20you%20are%20a%20web%20developer%20or%20a%20self-hosting%20business%20owner%2C%20the%20only%20excuse%20for%20not%20activating%20compression%20capabilities%20of%20your%20web%20server%20can%20be%20that%20you%20didn%27t%20know%20about%20it.%20And%20now%20that%20you%20are%20re&amp;short_link=http://bit.ly/c6Upm4&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%24%7Btitle%7D+-+%24%7Bshort_link%7D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li
class="shr-facebook"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Make+Your+Site+Lightning+Fast%2A+By+Compressing+%28deflate%2Fgzip%29+Your+HTML%2C+Javascript%2C+CSS%2C+XML%2C+etc+In+Apache&amp;link=http://beerpla.net/2009/06/09/how-to-make-your-site-lightning-fast-by-compressing-deflategzip-your-html-javascript-css-xml-etc-in-apache/&amp;notes=%2A%20Lightning%20Fast%20is%20a%20blatant%20exaggeration.%20Got%20you%20to%20look%20though%2C%20didn%27t%20it%3F%20%20Introduction%20%20Whether%20you%20are%20a%20web%20developer%20or%20a%20self-hosting%20business%20owner%2C%20the%20only%20excuse%20for%20not%20activating%20compression%20capabilities%20of%20your%20web%20server%20can%20be%20that%20you%20didn%27t%20know%20about%20it.%20And%20now%20that%20you%20are%20re&amp;short_link=http://bit.ly/c6Upm4&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a></li><li
class="shr-googlebuzz"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Make+Your+Site+Lightning+Fast%2A+By+Compressing+%28deflate%2Fgzip%29+Your+HTML%2C+Javascript%2C+CSS%2C+XML%2C+etc+In+Apache&amp;link=http://beerpla.net/2009/06/09/how-to-make-your-site-lightning-fast-by-compressing-deflategzip-your-html-javascript-css-xml-etc-in-apache/&amp;notes=%2A%20Lightning%20Fast%20is%20a%20blatant%20exaggeration.%20Got%20you%20to%20look%20though%2C%20didn%27t%20it%3F%20%20Introduction%20%20Whether%20you%20are%20a%20web%20developer%20or%20a%20self-hosting%20business%20owner%2C%20the%20only%20excuse%20for%20not%20activating%20compression%20capabilities%20of%20your%20web%20server%20can%20be%20that%20you%20didn%27t%20know%20about%20it.%20And%20now%20that%20you%20are%20re&amp;short_link=http://bit.ly/c6Upm4&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=257&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a></li><li
class="shr-reddit"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Make+Your+Site+Lightning+Fast%2A+By+Compressing+%28deflate%2Fgzip%29+Your+HTML%2C+Javascript%2C+CSS%2C+XML%2C+etc+In+Apache&amp;link=http://beerpla.net/2009/06/09/how-to-make-your-site-lightning-fast-by-compressing-deflategzip-your-html-javascript-css-xml-etc-in-apache/&amp;notes=%2A%20Lightning%20Fast%20is%20a%20blatant%20exaggeration.%20Got%20you%20to%20look%20though%2C%20didn%27t%20it%3F%20%20Introduction%20%20Whether%20you%20are%20a%20web%20developer%20or%20a%20self-hosting%20business%20owner%2C%20the%20only%20excuse%20for%20not%20activating%20compression%20capabilities%20of%20your%20web%20server%20can%20be%20that%20you%20didn%27t%20know%20about%20it.%20And%20now%20that%20you%20are%20re&amp;short_link=http://bit.ly/c6Upm4&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a></li><li
class="shr-hackernews"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Make+Your+Site+Lightning+Fast%2A+By+Compressing+%28deflate%2Fgzip%29+Your+HTML%2C+Javascript%2C+CSS%2C+XML%2C+etc+In+Apache&amp;link=http://beerpla.net/2009/06/09/how-to-make-your-site-lightning-fast-by-compressing-deflategzip-your-html-javascript-css-xml-etc-in-apache/&amp;notes=%2A%20Lightning%20Fast%20is%20a%20blatant%20exaggeration.%20Got%20you%20to%20look%20though%2C%20didn%27t%20it%3F%20%20Introduction%20%20Whether%20you%20are%20a%20web%20developer%20or%20a%20self-hosting%20business%20owner%2C%20the%20only%20excuse%20for%20not%20activating%20compression%20capabilities%20of%20your%20web%20server%20can%20be%20that%20you%20didn%27t%20know%20about%20it.%20And%20now%20that%20you%20are%20re&amp;short_link=http://bit.ly/c6Upm4&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=202&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a></li><li
class="shr-delicious"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Make+Your+Site+Lightning+Fast%2A+By+Compressing+%28deflate%2Fgzip%29+Your+HTML%2C+Javascript%2C+CSS%2C+XML%2C+etc+In+Apache&amp;link=http://beerpla.net/2009/06/09/how-to-make-your-site-lightning-fast-by-compressing-deflategzip-your-html-javascript-css-xml-etc-in-apache/&amp;notes=%2A%20Lightning%20Fast%20is%20a%20blatant%20exaggeration.%20Got%20you%20to%20look%20though%2C%20didn%27t%20it%3F%20%20Introduction%20%20Whether%20you%20are%20a%20web%20developer%20or%20a%20self-hosting%20business%20owner%2C%20the%20only%20excuse%20for%20not%20activating%20compression%20capabilities%20of%20your%20web%20server%20can%20be%20that%20you%20didn%27t%20know%20about%20it.%20And%20now%20that%20you%20are%20re&amp;short_link=http://bit.ly/c6Upm4&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=2&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li
class="shr-stumbleupon"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Make+Your+Site+Lightning+Fast%2A+By+Compressing+%28deflate%2Fgzip%29+Your+HTML%2C+Javascript%2C+CSS%2C+XML%2C+etc+In+Apache&amp;link=http://beerpla.net/2009/06/09/how-to-make-your-site-lightning-fast-by-compressing-deflategzip-your-html-javascript-css-xml-etc-in-apache/&amp;notes=%2A%20Lightning%20Fast%20is%20a%20blatant%20exaggeration.%20Got%20you%20to%20look%20though%2C%20didn%27t%20it%3F%20%20Introduction%20%20Whether%20you%20are%20a%20web%20developer%20or%20a%20self-hosting%20business%20owner%2C%20the%20only%20excuse%20for%20not%20activating%20compression%20capabilities%20of%20your%20web%20server%20can%20be%20that%20you%20didn%27t%20know%20about%20it.%20And%20now%20that%20you%20are%20re&amp;short_link=http://bit.ly/c6Upm4&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li
class="shr-mail"> <a
href="http://www.shareaholic.com/api/share/?title=How%20To%20Make%20Your%20Site%20Lightning%20Fast%2A%20By%20Compressing%20%28deflate%2Fgzip%29%20Your%20HTML%2C%20Javascript%2C%20CSS%2C%20XML%2C%20etc%20In%20Apache&amp;link=http://beerpla.net/2009/06/09/how-to-make-your-site-lightning-fast-by-compressing-deflategzip-your-html-javascript-css-xml-etc-in-apache/&amp;notes=%2A%20Lightning%20Fast%20is%20a%20blatant%20exaggeration.%20Got%20you%20to%20look%20though%2C%20didn%27t%20it%3F%20%20Introduction%20%20Whether%20you%20are%20a%20web%20developer%20or%20a%20self-hosting%20business%20owner%2C%20the%20only%20excuse%20for%20not%20activating%20compression%20capabilities%20of%20your%20web%20server%20can%20be%20that%20you%20didn%27t%20know%20about%20it.%20And%20now%20that%20you%20are%20re&amp;short_link=http://bit.ly/c6Upm4&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=201&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a></li></ul><div
style="clear: both;"></div></div> Similar Posts:<ul><li><a
href="http://beerpla.net/2008/03/29/beer-planet-upgraded-to-wordpress-25/" rel="bookmark" title="March 29, 2008">Beer Planet Upgraded To WordPress 2.5</a></li><li><a
href="http://beerpla.net/2010/01/13/wordpress-plugin-development-how-to-include-css-and-javascript-conditionally-and-only-when-needed-by-the-posts/" rel="bookmark" title="January 13, 2010">[WordPress Plugin Development] How To Include CSS and JavaScript Conditionally And Only When Needed By The Posts</a></li><li><a
href="http://beerpla.net/2009/06/21/hidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists/" rel="bookmark" title="June 21, 2009">Hidden Features Of Perl, PHP, Javascript, C, C++, C#, Java, Ruby, Python, And Others [Collection Of Incredibly Useful Lists]</a></li><li><a
href="http://beerpla.net/2006/06/12/rendr-a-live-awesome-csshtml-rendering-tool/" rel="bookmark" title="June 12, 2006">Rendr &#8211; a Live Awesome CSS/HTML Rendering Tool</a></li><li><a
href="http://beerpla.net/2007/10/12/cpan-the-perl-module-manager/" rel="bookmark" title="October 12, 2007">cpan &#8211; The Perl Module Manager</a></li></ul><p><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbeerpla.net%2F2009%2F06%2F09%2Fhow-to-make-your-site-lightning-fast-by-compressing-deflategzip-your-html-javascript-css-xml-etc-in-apache%2F&amp;title=How%20To%20Make%20Your%20Site%20Lightning%20Fast%2A%20By%20Compressing%20%28deflate%2Fgzip%29%20Your%20HTML%2C%20Javascript%2C%20CSS%2C%20XML%2C%20etc%20In%20Apache" id="wpa2a_6"><img
src="http://beerpla.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://beerpla.net/2009/06/09/how-to-make-your-site-lightning-fast-by-compressing-deflategzip-your-html-javascript-css-xml-etc-in-apache/feed/</wfw:commentRss> <slash:comments>19</slash:comments> </item> <item><title>How To Add A File Extension To vim Syntax Highlighting</title><link>http://beerpla.net/2008/04/02/how-to-add-a-vim-file-extension-to-syntax-highlighting/</link> <comments>http://beerpla.net/2008/04/02/how-to-add-a-vim-file-extension-to-syntax-highlighting/#comments</comments> <pubDate>Thu, 03 Apr 2008 05:10:53 +0000</pubDate> <dc:creator>Artem Russakovskii</dc:creator> <category><![CDATA[Databases]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[.vimrc]]></category> <category><![CDATA[dump]]></category> <category><![CDATA[highlight]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[syntax]]></category> <category><![CDATA[vim]]></category> <category><![CDATA[xml]]></category> <guid
isPermaLink="false">http://beerpla.net/?p=311</guid> <description><![CDATA[<p>Today I was asked a question about defining custom extensions for vim syntax highlighting such that, for example, vim would know that example.lmx is actually of type xml and apply xml syntax highlighting to it. I know vim already automatically does it not just based on extension but by looking for certain strings inside the text, like <em>&#60;?xml</em> but what if my file doesn&#039;t have such strings?</p><p
align="center"><a
href="http://beerpla.net/wp-content/uploads/HowToAddAvimFileExtensionToSyntaxHighlig_13140/image.png" class="lightview" rel="gallery['311']"><img
alt="image" src="http://beerpla.net/wp-content/uploads/HowToAddAvimFileExtensionToSyntaxHighlig_13140/image_thumb.png" width="681" height="126" /></a></p><p>After digging around I found the solution. Add the following to ~/.vimrc (the vim configuration file):</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
</pre></td><td
class="code"><pre>syntax on
filetype on
au BufNewFile,BufRead *.lmx set filetype=xml</pre></td></tr></table></div><p>After applying it, my .lmx file is highlighted:</p><p
align="center"><a
href="http://beerpla.net/wp-content/uploads/HowToAddAvimFileExtensionToSyntaxHighlig_13140/image_3.png" class="lightview" rel="gallery['311']"><img
alt="image" src="http://beerpla.net/wp-content/uploads/HowToAddAvimFileExtensionToSyntaxHighlig_13140/image_thumb_3.png" width="675" height="134" /></a></p><p
align="left">Same principle works, for instance, for mysql dumps that I have to do from time to time. ...<div
class=clear></div> <a
href="http://beerpla.net/2008/04/02/how-to-add-a-vim-file-extension-to-syntax-highlighting/" class="read_more"><div
class=excerpt-end>Read the rest of this article &#187;</div></a></p>]]></description> <content:encoded><![CDATA[<p>Today I was asked a question about defining custom extensions for vim syntax highlighting such that, for example, vim would know that example.lmx is actually of type xml and apply xml syntax highlighting to it. I know vim already automatically does it not just based on extension but by looking for certain strings inside the text, like <em>&lt;?xml</em> but what if my file doesn&#039;t have such strings?</p></p><p
align="center"><a
href="http://beerpla.net/wp-content/uploads/HowToAddAvimFileExtensionToSyntaxHighlig_13140/image.png" class="lightview" rel="gallery['311']"><img
alt="image" src="http://beerpla.net/wp-content/uploads/HowToAddAvimFileExtensionToSyntaxHighlig_13140/image_thumb.png" width="681" height="126" /></a></p><p>After digging around I found the solution. Add the following to ~/.vimrc (the vim configuration file):</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
</pre></td><td
class="code"><pre>syntax on
filetype on
au BufNewFile,BufRead *.lmx set filetype=xml</pre></td></tr></table></div><p>After applying it, my .lmx file is highlighted:</p><p
align="center"><a
href="http://beerpla.net/wp-content/uploads/HowToAddAvimFileExtensionToSyntaxHighlig_13140/image_3.png" class="lightview" rel="gallery['311']"><img
alt="image" src="http://beerpla.net/wp-content/uploads/HowToAddAvimFileExtensionToSyntaxHighlig_13140/image_thumb_3.png" width="675" height="134" /></a></p><p
align="left">Same principle works, for instance, for mysql dumps that I have to do from time to time. If they don&#039;t have a .sql extension, you&#039;ll get something like:</p><p
align="center"><a
href="http://beerpla.net/wp-content/uploads/HowToAddAvimFileExtensionToSyntaxHighlig_13140/image_4.png" class="lightview" rel="gallery['311']"><img
alt="image" src="http://beerpla.net/wp-content/uploads/HowToAddAvimFileExtensionToSyntaxHighlig_13140/image_thumb_4.png" width="640" height="158" /></a></p><p
align="left">After</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
</pre></td><td
class="code"><pre>syntax on
filetype on
au BufNewFile,BufRead *.dump set filetype=sql</pre></td></tr></table></div><p
align="left">everything is fine:</p><p
align="center"><a
href="http://beerpla.net/wp-content/uploads/HowToAddAvimFileExtensionToSyntaxHighlig_13140/image_5.png" class="lightview" rel="gallery['311']"><img
alt="image" src="http://beerpla.net/wp-content/uploads/HowToAddAvimFileExtensionToSyntaxHighlig_13140/image_thumb_5.png" width="640" height="153" /></a></p><p
align="left">But why and how does it work, you ask?</p><table
border="1" cellspacing="0" cellpadding="2" width="658"><tbody><tr><td
valign="top" width="150">:help au</td><td
valign="top" width="504">:au[tocmd] [group] {event} {pat} [nested] {cmd}<br
/> <br
/>Add {cmd} to the list of commands that Vim will execute automatically on {event} for a file matching {pat}.</td></tr><tr><td
valign="top" width="150">:help BufNewFile</td><td
valign="top" width="504">When starting to edit a file that doesn&#039;t exist.</td></tr><tr><td
valign="top" width="150">:help BufRead</td><td
valign="top" width="504">When starting to edit a new buffer, after reading the file into the buffer.</td></tr><tr><td
valign="top" width="150">:help filetype</td><td
valign="top" width="504">will actually tell this whole story in part B.</td></tr></tbody></table><p>And that&#039;s how you do it, folks.</p><div
class="shr-bookmarks shr-bookmarks-expand"><ul
class="socials"><li
class="shr-twitter"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Add+A+File+Extension+To+vim+Syntax+Highlighting&amp;link=http://beerpla.net/2008/04/02/how-to-add-a-vim-file-extension-to-syntax-highlighting/&amp;notes=Today%20I%20was%20asked%20a%20question%20about%20defining%20custom%20extensions%20for%20vim%20syntax%20highlighting%20such%20that%2C%20for%20example%2C%20vim%20would%20know%20that%20example.lmx%20is%20actually%20of%20type%20xml%20and%20apply%20xml%20syntax%20highlighting%20to%20it.%20I%20know%20vim%20already%20automatically%20does%20it%20not%20just%20based%20on%20extension%20but%20by%20looking%20for%20c&amp;short_link=http://bit.ly/cqYg3H&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%24%7Btitle%7D+-+%24%7Bshort_link%7D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li
class="shr-facebook"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Add+A+File+Extension+To+vim+Syntax+Highlighting&amp;link=http://beerpla.net/2008/04/02/how-to-add-a-vim-file-extension-to-syntax-highlighting/&amp;notes=Today%20I%20was%20asked%20a%20question%20about%20defining%20custom%20extensions%20for%20vim%20syntax%20highlighting%20such%20that%2C%20for%20example%2C%20vim%20would%20know%20that%20example.lmx%20is%20actually%20of%20type%20xml%20and%20apply%20xml%20syntax%20highlighting%20to%20it.%20I%20know%20vim%20already%20automatically%20does%20it%20not%20just%20based%20on%20extension%20but%20by%20looking%20for%20c&amp;short_link=http://bit.ly/cqYg3H&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a></li><li
class="shr-googlebuzz"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Add+A+File+Extension+To+vim+Syntax+Highlighting&amp;link=http://beerpla.net/2008/04/02/how-to-add-a-vim-file-extension-to-syntax-highlighting/&amp;notes=Today%20I%20was%20asked%20a%20question%20about%20defining%20custom%20extensions%20for%20vim%20syntax%20highlighting%20such%20that%2C%20for%20example%2C%20vim%20would%20know%20that%20example.lmx%20is%20actually%20of%20type%20xml%20and%20apply%20xml%20syntax%20highlighting%20to%20it.%20I%20know%20vim%20already%20automatically%20does%20it%20not%20just%20based%20on%20extension%20but%20by%20looking%20for%20c&amp;short_link=http://bit.ly/cqYg3H&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=257&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a></li><li
class="shr-reddit"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Add+A+File+Extension+To+vim+Syntax+Highlighting&amp;link=http://beerpla.net/2008/04/02/how-to-add-a-vim-file-extension-to-syntax-highlighting/&amp;notes=Today%20I%20was%20asked%20a%20question%20about%20defining%20custom%20extensions%20for%20vim%20syntax%20highlighting%20such%20that%2C%20for%20example%2C%20vim%20would%20know%20that%20example.lmx%20is%20actually%20of%20type%20xml%20and%20apply%20xml%20syntax%20highlighting%20to%20it.%20I%20know%20vim%20already%20automatically%20does%20it%20not%20just%20based%20on%20extension%20but%20by%20looking%20for%20c&amp;short_link=http://bit.ly/cqYg3H&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a></li><li
class="shr-hackernews"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Add+A+File+Extension+To+vim+Syntax+Highlighting&amp;link=http://beerpla.net/2008/04/02/how-to-add-a-vim-file-extension-to-syntax-highlighting/&amp;notes=Today%20I%20was%20asked%20a%20question%20about%20defining%20custom%20extensions%20for%20vim%20syntax%20highlighting%20such%20that%2C%20for%20example%2C%20vim%20would%20know%20that%20example.lmx%20is%20actually%20of%20type%20xml%20and%20apply%20xml%20syntax%20highlighting%20to%20it.%20I%20know%20vim%20already%20automatically%20does%20it%20not%20just%20based%20on%20extension%20but%20by%20looking%20for%20c&amp;short_link=http://bit.ly/cqYg3H&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=202&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a></li><li
class="shr-delicious"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Add+A+File+Extension+To+vim+Syntax+Highlighting&amp;link=http://beerpla.net/2008/04/02/how-to-add-a-vim-file-extension-to-syntax-highlighting/&amp;notes=Today%20I%20was%20asked%20a%20question%20about%20defining%20custom%20extensions%20for%20vim%20syntax%20highlighting%20such%20that%2C%20for%20example%2C%20vim%20would%20know%20that%20example.lmx%20is%20actually%20of%20type%20xml%20and%20apply%20xml%20syntax%20highlighting%20to%20it.%20I%20know%20vim%20already%20automatically%20does%20it%20not%20just%20based%20on%20extension%20but%20by%20looking%20for%20c&amp;short_link=http://bit.ly/cqYg3H&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=2&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li
class="shr-stumbleupon"> <a
href="http://www.shareaholic.com/api/share/?title=How+To+Add+A+File+Extension+To+vim+Syntax+Highlighting&amp;link=http://beerpla.net/2008/04/02/how-to-add-a-vim-file-extension-to-syntax-highlighting/&amp;notes=Today%20I%20was%20asked%20a%20question%20about%20defining%20custom%20extensions%20for%20vim%20syntax%20highlighting%20such%20that%2C%20for%20example%2C%20vim%20would%20know%20that%20example.lmx%20is%20actually%20of%20type%20xml%20and%20apply%20xml%20syntax%20highlighting%20to%20it.%20I%20know%20vim%20already%20automatically%20does%20it%20not%20just%20based%20on%20extension%20but%20by%20looking%20for%20c&amp;short_link=http://bit.ly/cqYg3H&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li
class="shr-mail"> <a
href="http://www.shareaholic.com/api/share/?title=How%20To%20Add%20A%20File%20Extension%20To%20vim%20Syntax%20Highlighting&amp;link=http://beerpla.net/2008/04/02/how-to-add-a-vim-file-extension-to-syntax-highlighting/&amp;notes=Today%20I%20was%20asked%20a%20question%20about%20defining%20custom%20extensions%20for%20vim%20syntax%20highlighting%20such%20that%2C%20for%20example%2C%20vim%20would%20know%20that%20example.lmx%20is%20actually%20of%20type%20xml%20and%20apply%20xml%20syntax%20highlighting%20to%20it.%20I%20know%20vim%20already%20automatically%20does%20it%20not%20just%20based%20on%20extension%20but%20by%20looking%20for%20c&amp;short_link=http://bit.ly/cqYg3H&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=201&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a></li></ul><div
style="clear: both;"></div></div> Similar Posts:<ul><li><a
href="http://beerpla.net/2008/04/16/mysql-conference-liveblogging-introduction-to-the-blob-streaming-project-wednesday-300pm/" rel="bookmark" title="April 16, 2008">MySQL Conference Liveblogging: Introduction To The BLOB Streaming Project (Wednesday 3:00PM)</a></li><li><a
href="http://beerpla.net/2008/04/09/some-useful-vim-commands-my-vim-cheatsheet/" rel="bookmark" title="April 9, 2008">Some Useful vim Commands &#8211; My vim Cheatsheet</a></li><li><a
href="http://beerpla.net/2008/03/12/mass-renaming-directories-and-files-using-total-commander/" rel="bookmark" title="March 12, 2008">Mass Renaming Directories And Files Using Total Commander</a></li><li><a
href="http://beerpla.net/2008/05/12/a-better-diff-or-what-to-do-when-gnu-diff-runs-out-of-memory-diff-memory-exhausted/" rel="bookmark" title="May 12, 2008">A Better diff Or What To Do When GNU diff Runs Out Of Memory (&quot;diff: memory exhausted&quot;)</a></li><li><a
href="http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/" rel="bookmark" title="November 4, 2009">[Android] Auto Formatting Android XML Files With Eclipse</a></li></ul><p><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbeerpla.net%2F2008%2F04%2F02%2Fhow-to-add-a-vim-file-extension-to-syntax-highlighting%2F&amp;title=How%20To%20Add%20A%20File%20Extension%20To%20vim%20Syntax%20Highlighting" id="wpa2a_8"><img
src="http://beerpla.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://beerpla.net/2008/04/02/how-to-add-a-vim-file-extension-to-syntax-highlighting/feed/</wfw:commentRss> <slash:comments>38</slash:comments> </item> </channel> </rss>
