<?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>Bart&#039;s notes</title>
	<atom:link href="http://notes.bartv.be/feed/" rel="self" type="application/rss+xml" />
	<link>http://notes.bartv.be</link>
	<description>This serves as my personal notebook which I share with the world</description>
	<lastBuildDate>Tue, 07 Jun 2011 07:40:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Tracking Facebook likes, shares and sends in Google Analytics</title>
		<link>http://notes.bartv.be/tracking-facebook-likes-shares-and-sends-in-google-analytics/</link>
		<comments>http://notes.bartv.be/tracking-facebook-likes-shares-and-sends-in-google-analytics/#comments</comments>
		<pubDate>Mon, 23 May 2011 08:32:46 +0000</pubDate>
		<dc:creator>bart</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[google analytics]]></category>

		<guid isPermaLink="false">http://notes.bartv.be/?p=116</guid>
		<description><![CDATA[TweetFollowing up on my previous post about Tracking External links with Google Analytics. Here&#8217;s something you can use to track Facebook likes and shares. We&#8217;ll track clicks using the Facebook Events. Note that this only works if you&#8217;re using FBML! Here&#8217;s the things we&#8217;re going to be tracking: Somebody clicks the &#8216;Like&#8217; button on your [...]]]></description>
			<content:encoded><![CDATA[<div id="tweetbutton116" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fbit.ly%2Fj7KQWE&amp;via=dotbart&amp;text=Tracking%20Facebook%20likes%2C%20shares%20and%20sends%20in%20Google%20Analytics&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fnotes.bartv.be%2Ftracking-facebook-likes-shares-and-sends-in-google-analytics%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://notes.bartv.be/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p>Following up on my previous post about <a href="http://notes.bartv.be/easily-track-outgoing-links-with-jquery-and-google-analytics/">Tracking External links with Google Analytics</a>. Here&#8217;s something you can use to track Facebook likes and shares.</p>
<p>
We&#8217;ll track clicks using the <a href="http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/" rel="nofollow">Facebook Events</a>. Note that this only works if you&#8217;re using <strong>FBML</strong>!<br />
Here&#8217;s the things we&#8217;re going to be tracking:</p>
<ul>
<li>Somebody clicks the &#8216;Like&#8217; button on your website to &#8216;Like&#8217; your Facebook page</li>
<li>Somebody clicks the &#8216;Like&#8217; button on your website to share the current page on his &#8216;Wall&#8217;</li>
<li>Somebody clicks the &#8216;Send&#8217; button to share this page with some friends on Facebook</li>
</ul>
<p>And it&#8217;s all in here:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">FB.<span style="color: #660066;">Event</span>.<span style="color: #660066;">subscribe</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;edge.create&quot;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>response.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;facebook.com&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                 <span style="color: #006600; font-style: italic;">//if the returned link contains 'facebook,com'. It's a 'Like' for your Facebook page</span>
		_gaq.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'_trackEvent'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Facebook'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Like'</span><span style="color: #339933;">,</span>response<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
                 <span style="color: #006600; font-style: italic;">//else, somebody is sharing the current page on their wall</span>
		_gaq.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'_trackEvent'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Facebook'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Share'</span><span style="color: #339933;">,</span>response<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
FB.<span style="color: #660066;">Event</span>.<span style="color: #660066;">subscribe</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;message.send&quot;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	_gaq.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'_trackEvent'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Facebook'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Send'</span><span style="color: #339933;">,</span>response<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>As you may have noticed, the Facebook event contains the liked/shared/sent link as <strong>response</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://notes.bartv.be/tracking-facebook-likes-shares-and-sends-in-google-analytics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easily track outgoing links with jQuery and Google Analytics</title>
		<link>http://notes.bartv.be/easily-track-outgoing-links-with-jquery-and-google-analytics/</link>
		<comments>http://notes.bartv.be/easily-track-outgoing-links-with-jquery-and-google-analytics/#comments</comments>
		<pubDate>Thu, 19 May 2011 09:12:49 +0000</pubDate>
		<dc:creator>bart</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[google analytics]]></category>
		<category><![CDATA[statistics]]></category>

		<guid isPermaLink="false">http://notes.bartv.be/?p=112</guid>
		<description><![CDATA[Tweet Outgoing links on your websites cause 3 things: Take linkjuice away from your page Drive traffic away from your webiste They don&#8217;t allow you to measure the amount of clicks on that link The first problem, you have to sort manually by adding the rel=&#8221;nofollow&#8221; attribute to all external links, as recommended by Google. [...]]]></description>
			<content:encoded><![CDATA[<div id="tweetbutton112" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fbit.ly%2FjziHkB&amp;via=dotbart&amp;text=Easily%20track%20outgoing%20links%20with%20jQuery%20and%20Google%20Analytics&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fnotes.bartv.be%2Feasily-track-outgoing-links-with-jquery-and-google-analytics%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://notes.bartv.be/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p>
Outgoing links on your websites cause 3 things:
</p>
<ul>
<li>Take <a href="http://www.seomoz.org/blog/pagerank-link-patterns-the-new-flow-of-link-juice" rel="nofollow">linkjuice</a> away from your page</li>
<li>Drive traffic away from your webiste</li>
<li>They don&#8217;t allow you to measure the amount of clicks on that link</a>
</ul>
<p>
The first problem, you have to sort manually by adding the <strong>rel=&#8221;nofollow&#8221;</strong> attribute to all external links, as <a href="http://www.google.com/support/webmasters/bin/answer.py?hl=nl&#038;answer=96569">recommended by Google</a>.
</p>
<p>
The second and third problem, can be easily fixed by using jQuery. I&#8217;ll show you how:
</p>
<h2>Opening external links in a new tab</h2>
<p>
By opening those links in a new tab, your page stays open, therefore not driving the user away from your page.<br />
Normally, this is done by manually appending <strong>target=&#8221;_blank&#8221;</strong> to each link. Let&#8217;s let jQuery do that for us.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a[@href^='http']&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'target'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'_blank'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>(Do note that I chose to define links starting with &#8216;http&#8217; as external links)
</p>
<h2>Tracking clicks on external Links</h2>
<p>
We can track links by using Google Analytics Event tracking:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a[@href^='http']&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        _gaq.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'_trackEvent'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'External Link'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Click'</span><span style="color: #339933;">,</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;href&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</p>
<h2>Putting it all together</h2>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a[@href^='http']&quot;</span><span style="color: #009900;">&#41;</span>
        .<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'target'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'_blank'</span><span style="color: #009900;">&#41;</span>
        .<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            _gaq.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'_trackEvent'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'External Link'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Click'</span><span style="color: #339933;">,</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;href&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Help! My internal links also start with &#8216;http&#8217;</h2>
<p>
No problem, you can do like me and borrow <a href="http://www.learningjquery.com/2008/08/quick-tip-dynamically-add-an-icon-for-external-links" rel="nofollow">this trick from Karl Swedberg</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">filter</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">hostname</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">hostname</span> <span style="color: #339933;">!==</span> location.<span style="color: #660066;">hostname</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'target'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'_blank'</span><span style="color: #009900;">&#41;</span>
.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    _gaq.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'_trackEvent'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'External Link'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Click'</span><span style="color: #339933;">,</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;href&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>
</p>
]]></content:encoded>
			<wfw:commentRss>http://notes.bartv.be/easily-track-outgoing-links-with-jquery-and-google-analytics/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Google AppEngine translate bot</title>
		<link>http://notes.bartv.be/google-appengine-translate-bot/</link>
		<comments>http://notes.bartv.be/google-appengine-translate-bot/#comments</comments>
		<pubDate>Fri, 13 May 2011 09:44:20 +0000</pubDate>
		<dc:creator>bart</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[appengine]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[translate]]></category>

		<guid isPermaLink="false">http://notes.bartv.be/?p=108</guid>
		<description><![CDATA[TweetGoogle provided a few translation bots recently. Since I do a lot of Dutch -&#62; French translation, I quicly whipped up my own and deployed it to Google AppEngine: For translating I used the unofficial google-api-translate-java jar file. Here&#8217;s what you need to do: Place the jar in war\WEB-INF\lib war\WEB-INF\web.xml &#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62; &#60;web-app xmlns:xsi=&#34;http://www.w3.org/2001/XMLSchema-instance&#34; [...]]]></description>
			<content:encoded><![CDATA[<div id="tweetbutton108" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fbit.ly%2FkoS9EV&amp;via=dotbart&amp;text=Google%20AppEngine%20translate%20bot&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fnotes.bartv.be%2Fgoogle-appengine-translate-bot%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://notes.bartv.be/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p>Google provided a few <a href="http://www.google.com/support/talk/bin/answer.py?answer=89921">translation bots</a> recently.<br />
Since I do a lot of Dutch -&gt; French translation, I quicly whipped up my own and deployed it to Google AppEngine:</p>
<p>For translating I used the unofficial <a href="http://code.google.com/p/google-api-translate-java/" target="_blank">google-api-translate-java</a> jar file.<br />
Here&#8217;s what you need to do:</p>
<p>Place the <strong>jar</strong> in <strong>war\WEB-INF\lib</strong></p>
<p><strong>war\WEB-INF\web.xml</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-app</span> <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">xmlns:web</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee</span>
<span style="color: #009900;">http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.5&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Translate_Bot<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>be.bartv.translatebot.Translate_BotServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Translate_Bot<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/translate_bot<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>xmppreceiver<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>be.bartv.translatebot.XMPPReceiverServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>xmppreceiver<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/_ah/xmpp/message/chat/<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;welcome-file-list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;welcome-file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>index.html<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/welcome-file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/welcome-file-list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>war\WEB-INF\appengine-web.xml</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;appengine-web-app</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://appengine.google.com/ns/1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>translate-bot<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- Configure java.util.logging --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system-properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;java.util.logging.config.file&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;WEB-INF/logging.properties&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system-properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;inbound-services<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>xmpp_message<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/inbound-services<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/appengine-web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>src\be.bartv.translatebot.XMPPReceiverServlet.java</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">be.bartv.translatebot</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServlet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletResponse</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.api.GoogleAPI</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.api.translate.Language</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.api.translate.Translate</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.appengine.api.xmpp.JID</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.appengine.api.xmpp.Message</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.appengine.api.xmpp.MessageBuilder</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.appengine.api.xmpp.XMPPService</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.appengine.api.xmpp.XMPPServiceFactory</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> XMPPReceiverServlet <span style="color: #000000; font-weight: bold;">extends</span> HttpServlet<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 2212159648921332999L<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> doPost<span style="color: #009900;">&#40;</span>HttpServletRequest req, HttpServletResponse resp<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>
	<span style="color: #009900;">&#123;</span>
		XMPPService service <span style="color: #339933;">=</span> XMPPServiceFactory.<span style="color: #006633;">getXMPPService</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		Message message <span style="color: #339933;">=</span> service.<span style="color: #006633;">parseMessage</span><span style="color: #009900;">&#40;</span>req<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		JID jid <span style="color: #339933;">=</span> message.<span style="color: #006633;">getFromJid</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">String</span> content 	<span style="color: #339933;">=</span> message.<span style="color: #006633;">getBody</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003399;">String</span> reply <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Hmmz. I Should return a translation now&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			GoogleAPI.<span style="color: #006633;">setHttpReferrer</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://notes.bartv.be/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			reply <span style="color: #339933;">=</span> Translate.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span>content, Language.<span style="color: #006633;">DUTCH</span>, Language.<span style="color: #006633;">FRENCH</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			reply <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Error occurred: &quot;</span><span style="color: #339933;">+</span>e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		service.<span style="color: #006633;">sendMessage</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> MessageBuilder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">withBody</span><span style="color: #009900;">&#40;</span>reply<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">withRecipientJids</span><span style="color: #009900;">&#40;</span>jid<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">build</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>
Sometimes, I do get a error saying I violate Google&#8217;s Terms and conditions. No idea why tho &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://notes.bartv.be/google-appengine-translate-bot/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Google Breadcrumbs come from &#8230; Breadcrumbs</title>
		<link>http://notes.bartv.be/google-breadcrumbs-come-from-breadcrumbs/</link>
		<comments>http://notes.bartv.be/google-breadcrumbs-come-from-breadcrumbs/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 07:08:55 +0000</pubDate>
		<dc:creator>bart</dc:creator>
				<category><![CDATA[SEO]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[breadcrumbs]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[seo]]></category>

		<guid isPermaLink="false">http://notes.bartv.be/?p=99</guid>
		<description><![CDATA[TweetGoogle sometimes shows breadcrumbs in their search results. Instead of showing the URL of the page you&#8217;re going to visit (in the green bit), hey&#8217;ll show a path kind of like so: Homepage › Category › Subcategory &#62; Something something. Many SEO experts have been trying to figure out just where they come from. So have I. [...]]]></description>
			<content:encoded><![CDATA[<div id="tweetbutton99" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fbit.ly%2FhG8rnR&amp;via=dotbart&amp;text=Google%20Breadcrumbs%20come%20from%20%26%238230%3B%20Breadcrumbs&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fnotes.bartv.be%2Fgoogle-breadcrumbs-come-from-breadcrumbs%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://notes.bartv.be/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p>Google sometimes shows breadcrumbs in their search results.<br />
Instead of showing the URL of the page you&#8217;re going to visit (in the <span style="color: #339966;">green</span> bit), hey&#8217;ll show a path kind of like so:<br />
<em>Homepage › Category › Subcategory &gt; Something something.</em><br />
Many SEO experts have been trying to figure out just where they come from. So have I.<br />
So recently, on one of my websites: <a rel="nofollow" href="http://www.promoties.be">promoties.be</a>. I had the chance to figure it out.</p>
<p>All promotions are divided into categories and subcategories. The URL of these categories are always hierarchically mapped.<br />
e.g. <a rel="nofollow" href="http://www.promoties.be/categorie/autos-motoren-27/aanhangwagens-1419">http://www.promoties.be/categorie/autos-motoren-27/aanhangwagens-1419</a> is a subcategory of <a rel="nofollow" href="http://www.promoties.be/categorie/autos-motoren-27/aanhangwagens-1419">http://www.promoties.be/categorie/autos-motoren-27</a> making the URL logically traversable.<br />
However a specific offer or product under this category is not in this structure. Mainly because that would make the URL way too long.<br />
An example is <a rel="nofollow" href="http://www.promoties.be/promotie-bw1-aanhangwagen-864809">http://www.promoties.be/promotie-bw1-aanhangwagen-864809</a>. As you can see, the categories do not appear in the URL.</p>
<p>However the breadcrumb for this offer is as follows: <strong>Home &gt; Promoties &gt; Auto&#8217;s &amp; Motoren &gt; Aanhangwagens &gt; Bw1 aanhangwagen </strong>with all the nested categories intact.</p>
<p>Now the Google search result block for this specific offer was the following:</p>
<div id="attachment_101" class="wp-caption alignnone" style="width: 667px"><a href="http://notes.bartv.be/wp-content/uploads/2011/03/Selectie_0391.png"><img class="size-full wp-image-101" title="Selectie_039" src="http://notes.bartv.be/wp-content/uploads/2011/03/Selectie_0391.png" alt="" width="657" height="73" /></a><p class="wp-caption-text">Google search result for &quot;Bw1 aanhangwagen&quot;</p></div>
<p><strong>In this case </strong>we can conclude that Google took the breadcrumbs in the search results, from the breadcrumbs on the page.</p>
<p>More info on breadcrumbs:<a href="http://www.google.com/support/webmasters/bin/answer.py?answer=185417"></p>
<p>http://www.google.com/support/webmasters/bin/answer.py?answer=185417</a></p>
]]></content:encoded>
			<wfw:commentRss>http://notes.bartv.be/google-breadcrumbs-come-from-breadcrumbs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>lib.js: Good practice and generally a good idea</title>
		<link>http://notes.bartv.be/lib-js-good-practice-and-generally-a-good-idea/</link>
		<comments>http://notes.bartv.be/lib-js-good-practice-and-generally-a-good-idea/#comments</comments>
		<pubDate>Fri, 04 Feb 2011 10:50:27 +0000</pubDate>
		<dc:creator>bart</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[pagespeed]]></category>
		<category><![CDATA[seo]]></category>

		<guid isPermaLink="false">http://notes.bartv.be/?p=90</guid>
		<description><![CDATA[TweetI recently stumbled upon an article on Six Revisions titled Are Current web design trends pushing us back to 1999?. I found it to be a very interesting article. It mainly talks about how new trends in the web are barking up old problems, like the Flash splash page, or the shoutbox. On thing I [...]]]></description>
			<content:encoded><![CDATA[<div id="tweetbutton90" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fbit.ly%2FicQ5En&amp;via=dotbart&amp;text=lib.js%3A%20Good%20practice%20and%20generally%20a%20good%20idea&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fnotes.bartv.be%2Flib-js-good-practice-and-generally-a-good-idea%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://notes.bartv.be/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p>I recently stumbled upon an article on Six Revisions titled <a href="http://sixrevisions.com/web_design/are-current-web-design-trends-pushing-us-back-to-1999/">Are Current web design trends pushing us back to 1999?</a>.</p>
<p>I found it to be a very interesting article. It mainly talks about how new trends in the web are barking up old problems, like the <a href="http://angryaussie.files.wordpress.com/2009/07/flash.jpg?w=499&#038;h=434">Flash splash page</a>, or the shoutbox.</p>
<p>
On thing I found very interesting was the part called <strong>Modern-Day Bloated, Cut-And-Paste Scripts</strong>.</p>
<p>Being involved with jQuery on a day-to-day basis, you start using some plugins, or even <a href="http://notes.bartv.be/jquery-plugin-development/">write some of your own</a>.<br />
But once you start stacking plugins, the browser has to load all of these plugins, generating more request. Which is generally a <a href="http://yuiblog.com/blog/2008/07/21/performance-research-part-6/">good idea</a>.<br />
<a href="http://notes.bartv.be/wp-content/uploads/2011/02/0005-13_plugins_code.png"><img src="http://notes.bartv.be/wp-content/uploads/2011/02/0005-13_plugins_code-300x272.png" alt="Bloated plugins" title="jQuery Plugins" width="300" height="272" class="alignnone size-medium wp-image-91" /></a>
</p>
<p>
Now whenever creating a new webproject, I use one JS file: <strong>lib.js</strong>. This JS file contains everything I need, it&#8217;s like a swiss pocket knife!<br />
Structure is usually like following (depends on your project needs):</p>
<ul>
<li>jQuery</li>
<li>jQuery UI</li>
<li>Plugins</li>
<li>$(document).ready(function(){ /**magic here **/});</li>
</ul>
<p>
You could argue by saying: but doesn&#8217;t the filesize increase by a lot, letting the user download a 250k file is quite a lot!<br />
I agree, but play your cards right in server configuration with a little help from <a href="http://notes.bartv.be/guide-to-googles-mod_apache/">Google&#8217;s mod_pagespeed</a> or simply by getting goot <strong>ETags</strong> or <strong>Expires headers</strong>, the load happens just once (!!). And the rest of your surfing experience stays snappy.</p>
]]></content:encoded>
			<wfw:commentRss>http://notes.bartv.be/lib-js-good-practice-and-generally-a-good-idea/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Force AJAX calls no-cache in Java. The clean way</title>
		<link>http://notes.bartv.be/force-ajax-calls-no-cache-in-java-the-clean-way/</link>
		<comments>http://notes.bartv.be/force-ajax-calls-no-cache-in-java-the-clean-way/#comments</comments>
		<pubDate>Tue, 25 Jan 2011 16:28:13 +0000</pubDate>
		<dc:creator>bart</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[expires]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://notes.bartv.be/?p=86</guid>
		<description><![CDATA[TweetRecently I discovered Internet Explorer caches some AJAX calls. I was using jQuery to make some AJAX calls in a web-admin interface I&#8217;m building. I noticed none of the data changed as I tried to refresh (using an AJAX call). conclusion:: IE caches AJAX calls&#8230; very annoying. You could go around and alter every method [...]]]></description>
			<content:encoded><![CDATA[<div id="tweetbutton86" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fbit.ly%2FikjrMw&amp;via=dotbart&amp;text=Force%20AJAX%20calls%20no-cache%20in%20Java.%20The%20clean%20way&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fnotes.bartv.be%2Fforce-ajax-calls-no-cache-in-java-the-clean-way%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://notes.bartv.be/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p>Recently I discovered Internet Explorer caches some AJAX calls.</p>
<p>I was using jQuery to make some AJAX calls in a web-admin interface I&#8217;m building. I noticed none of the data changed as I tried to refresh (using an AJAX call). <strong>conclusion:</strong>: IE caches AJAX calls&#8230; very annoying.</p>
<p>
You could go around and alter every method in your Struts/Spring/&#8230; application to force <a href="http://support.microsoft.com/kb/234067">no-cache</a>. But that would take some time. Instead, I wrote a Filter.</p>
<p>Hold on though, you don&#8217;t want every page to get the no-cache headers, that would seriously decrease your site performance (all pages would be force-reloaded instead of browser-cached). So we&#8217;ll only filter out AJAX calls.
</p>
<p>
Luckily, jQuery passes a header argument: <strong>X-Requested-With: XmlHttpRequest</strong><br />
<div id="attachment_87" class="wp-caption alignnone" style="width: 310px"><a href="http://notes.bartv.be/wp-content/uploads/2011/01/x-requested-with.png"><img src="http://notes.bartv.be/wp-content/uploads/2011/01/x-requested-with-300x130.png" alt="x-requested-with header" title="x-requested-with" width="300" height="130" class="size-medium wp-image-87" /></a><p class="wp-caption-text">X-Requested-With</p></div></p>
<h2>The Code!</h2>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.Filter</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.FilterChain</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.FilterConfig</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletResponse</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletResponse</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AjaxCacheFilter <span style="color: #000000; font-weight: bold;">implements</span> Filter<span style="color: #009900;">&#123;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> destroy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> doFilter<span style="color: #009900;">&#40;</span>ServletRequest request, ServletResponse response,FilterChain chain<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>, ServletException <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;XMLHttpRequest&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>HttpServletRequest<span style="color: #009900;">&#41;</span> request<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;x-requested-with&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>HttpServletResponse<span style="color: #009900;">&#41;</span>response<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setDateHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Expires&quot;</span>, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>HttpServletResponse<span style="color: #009900;">&#41;</span>response<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">addHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cache-Control&quot;</span>, <span style="color: #0000ff;">&quot;no-cache&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>HttpServletResponse<span style="color: #009900;">&#41;</span>response<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">addHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Pragma&quot;</span>, <span style="color: #0000ff;">&quot;No-Cache&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
		chain.<span style="color: #006633;">doFilter</span><span style="color: #009900;">&#40;</span>request, response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span>FilterConfig arg0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException <span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And add it as the last filter in your web.xml</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ajaxCache<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		com.yoursite.web.filters.AjaxCacheFilter
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ajaxCache<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dispatcher<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>FORWARD<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dispatcher<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dispatcher<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>REQUEST<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dispatcher<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Hope it helps somebody! If you used it, let me know in comments. I&#8217;d love to know!</p>
]]></content:encoded>
			<wfw:commentRss>http://notes.bartv.be/force-ajax-calls-no-cache-in-java-the-clean-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Executing Javascript from an external Iframe</title>
		<link>http://notes.bartv.be/executing-javascript-from-an-external-iframe/</link>
		<comments>http://notes.bartv.be/executing-javascript-from-an-external-iframe/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 09:43:22 +0000</pubDate>
		<dc:creator>bart</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[external]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[iframe]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://notes.bartv.be/?p=79</guid>
		<description><![CDATA[TweetWhats the problem? Maybe you&#8217;ve made a deal with a partner website, or you&#8217;re just loading a page from another server. The point is: You&#8217;ve got an IFrame on your page coming from another domain. All is well (except for Google, they don&#8217;t like iframes) untill you want some client-side interaction coming from that page. [...]]]></description>
			<content:encoded><![CDATA[<div id="tweetbutton79" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fbit.ly%2Fg8pVwD&amp;via=dotbart&amp;text=Executing%20Javascript%20from%20an%20external%20Iframe&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fnotes.bartv.be%2Fexecuting-javascript-from-an-external-iframe%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://notes.bartv.be/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><h2>Whats the problem?</h2>
<p>Maybe you&#8217;ve made a deal with a partner website, or you&#8217;re just loading a page from another server. The point is: You&#8217;ve got an IFrame on your page coming from another domain.<br />
All is well (except for Google, they don&#8217;t like iframes) untill you want some client-side interaction coming from that page.
</p>
<p>
But now you&#8217;ve reached the point where you want some client-side interaction from that IFrame. &#8220;Great!&#8221; you say. I&#8217;ll just put JS in the IFrame, and I&#8217;ll be fine. But hold your horses cowboy, there&#8217;s 2 things stopping you as a great developer from doing so:</p>
<ul>
<li>Don&#8217;t have you JS scattered, have it nice and organised, centralized</li>
<li>You&#8217;re visually constrained to the IFrame</li>
</ul>
<h2>So how do we execute JS on the parent frame?</h2>
<p>Directly from the IFrame? You can&#8217;t! Sandbox specifications say you can&#8217;t call functions defined in pages coming from another domain (kind of like loading JSON/Ajax from another domain).</p>
<p>
But in that problem also lies the solution: just load a Proxy page from the other server!<br />
Let me make myself a bit more clear through some Graphs:
</p>
<p>Normally, you&#8217;de have 2 pages, page A contains an Iframe to page B:<br />
<img src="https://chart.googleapis.com/chart?cht=gv&#038;chl=digraph{A-%3EB}&#038;chs=150x150" alt="Page A to Page B" /><br />
Now we&#8217;re introducting a Proxy page, on the same server as page A. Page B contains a IFrame to the proxy page:<br />
<img src="https://chart.googleapis.com/chart?cht=gv&#038;chl=digraph{A-%3EB-%3EProxyA}&#038;chs=150x150" alt="Page A to B to Proxy" /><br />
<strong>All Done!</strong> Now you can execute JS, like so:<br />
<img src="https://chart.googleapis.com/chart?cht=gv&#038;chl=digraph{A-%3EB-%3EProxyA-%3EA}&#038;chs=150x150" alt="all done" />
</p>
<h2>The Code!</h2>
<p>So how do we do it? Here you go!<br />
<strong>index.html</strong> (on your server)</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
			function alertme(str)
			{
				alert(&quot;String: &quot; + str);
			}
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">iframe</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://yourpartner.com/iframe.htm&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">iframe</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p><strong>proxy.html</strong> (on your server)</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
			function gup( name )
			{
			  name = name.replace(/[\[]/,&quot;\\\[&quot;).replace(/[\]]/,&quot;\\\]&quot;);
			  var regexS = &quot;[\\?<span style="color: #ddbb00;">&amp;]&quot;+name+&quot;=([^&amp;#]*)&quot;;</span>
			  var regex = new RegExp( regexS );
			  var results = regex.exec( window.location.href );
			  if( results == null )
			    return &quot;&quot;;
			  else
			    return results[1];
			}
			eval(&quot;top.&quot;+gup(&quot;execute&quot;));
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>And finally!<br />
<strong>iframe.html</strong> (on any other server)</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
        Hi There!
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">iframe</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://yourserver.com/proxy.html?execute=alertme(123);&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">iframe</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<h2>What you did there, I don&#8217;t quite see it</h2>
<p>
In the page on the other server, I pass a function call as an argument to my proxy.<br />
My proxy then gets this function out of the parameter, and executes it through eval()!
</p>
<h2>Warning</h2>
<p>Handle with care, allowing anyone to simply execute JS on/from your server through a parameter just opens up a whole new spectrum of <a href="http://en.wikipedia.org/wiki/Cross-site_scripting" target="_new">XSS attacks</a>.<br />
That sandbox was created for a reason!</p>
]]></content:encoded>
			<wfw:commentRss>http://notes.bartv.be/executing-javascript-from-an-external-iframe/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Guide to Google&#8217;s mod_pagespeed</title>
		<link>http://notes.bartv.be/guide-to-googles-mod_apache/</link>
		<comments>http://notes.bartv.be/guide-to-googles-mod_apache/#comments</comments>
		<pubDate>Fri, 03 Dec 2010 21:29:54 +0000</pubDate>
		<dc:creator>bart</dc:creator>
				<category><![CDATA[SEO]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[mod_pagespeed]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[speed]]></category>

		<guid isPermaLink="false">http://notes.bartv.be/?p=72</guid>
		<description><![CDATA[TweetGoogle recently released a specific Apache mod: mod_pagespeed. Here are my findings: Introduction: goal Often, when developing websites/webapplications, you find yourself telling yourself: I&#8217;ll quickly write that piece of CSS inline or Fudge it, I&#8217;ll leave compressing that piece of JavaScript for when I get out of development phase and maybe even never mind resizing [...]]]></description>
			<content:encoded><![CDATA[<div id="tweetbutton72" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fbit.ly%2Fhx2ZKx&amp;via=dotbart&amp;text=Guide%20to%20Google%26%238217%3Bs%20mod_pagespeed&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fnotes.bartv.be%2Fguide-to-googles-mod_apache%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://notes.bartv.be/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p>Google recently released a specific <a href="http://httpd.apache.org/" target="_new">Apache</a> mod: <a href="http://code.google.com/p/modpagespeed/" target="_new">mod_pagespeed</a>.<br />
Here are my findings:</p>
<h2>Introduction: goal</h2>
<p>
Often, when developing websites/webapplications, you find yourself telling yourself: <em>I&#8217;ll quickly write that piece of CSS inline</em> or <em>Fudge it, I&#8217;ll leave compressing that piece of JavaScript for when I get out of development phase</em> and maybe even <em>never mind resizing that image, I&#8217;ll just use &#8216;width&#8217; and &#8216;height&#8217; to get the dimensions right.</em><br />
And oh how you promise yourself you&#8217;ll fix those issues later. But let&#8217;s be honest: deadlines are cruel.
</p>
<p>
So a lot of websites go live without a lot of speed omtimizations. They get a bad score in <a href="http://developer.yahoo.com/yslow/" target="_new">YSlow</a> or <a href="http://code.google.com/intl/nl-NL/speed/page-speed/" target="_new">PageSpeed</a>.<br />
And the word on the street is, google prefers website that load faster!
</p>
<p>
Optimizing your CSS/JS/Images takes time. Compressing your content, combining CSS/JS also makes it difficult to adjust any of these later. You&#8217;ll have to dig through compacted code. Nobody likes that.
</p>
<h2>The solution</h2>
<p>The new mod_pagespeed is an Apache Output Filter. This means your website renders your website (in PHP, Java, Ruby, &#8230;) and just before Apache serves your HTML page to the browser, this thing comes into action.</p>
<p>
You can configure it to do a lot of things. I listed the ones I find most important below. But you can get the <a href="http://code.google.com/intl/nl-NL/speed/page-speed/docs/filters.html" target="_new">full feature list here</a></p>
<ul>
<li>Compress CSS and JS (less traffic)</li>
<li>Move inline CSS/JS to an external file (so they can get cached)</li>
<li>Combine external CSS/JS to one file (less requests)</li>
<li>Caching (of HTML,CSS,JS,images)</li>
<li>Automatically resize images based on the &#8216;width&#8217; and &#8216;height&#8217; attributes of an img-tag (less traffic)</li>
<li>Add &#8216;width&#8217; and &#8216;height&#8217; attributes if you forgot any (usability)</li>
<li>Base64 encode images and include them in HTML when small (less requests)</li>
</ul>
<p>Bottomline: it&#8217;s genius
</p>
<h2>My Configuration</h2>
<p>I played around with mod_pagespeed today. Here&#8217;s the configuration I came up with (I added comments)<br />
(your configuration resides in /etc/apache2/mods-enabled/pagespeed.conf)</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">IfModule</span> pagespeed_module&gt;
	ModPagespeed <span style="color: #0000ff;">on</span>
	<span style="color: #00007f;">AddOutputFilterByType</span> MOD_PAGESPEED_OUTPUT_FILTER text/html
&nbsp;
	ModPagespeedFileCachePath            <span style="color: #7f007f;">&quot;/var/mod_pagespeed/cache/&quot;</span>
	ModPagespeedGeneratedFilePrefix      <span style="color: #7f007f;">&quot;/var/mod_pagespeed/files/&quot;</span>
&nbsp;
	ModPagespeedRewriteLevel CoreFilters
&nbsp;
&nbsp;
	ModPagespeedFileCachePath            <span style="color: #7f007f;">&quot;/var/mod_pagespeed/cache/&quot;</span>
	ModPagespeedGeneratedFilePrefix      <span style="color: #7f007f;">&quot;/var/mod_pagespeed/files/&quot;</span>
	<span style="color: #adadad; font-style: italic;">#Add head section to HTML (if not already there)</span>
	ModPagespeedEnableFilters add_head
	<span style="color: #adadad; font-style: italic;">#Move CSS and JS to outline (external file)</span>
	ModPagespeedEnableFilters outline_css,outline_javascript
	<span style="color: #adadad; font-style: italic;">#If inline CSS is used, move this to head section</span>
	ModPagespeedEnableFilters move_css_to_head
	<span style="color: #adadad; font-style: italic;">#Combine external CSS files to 1 fil</span>
	ModPagespeedEnableFilters combine_css
	<span style="color: #adadad; font-style: italic;">#Compress CSS and JS by removing whitespace/comments</span>
	ModPagespeedEnableFilters rewrite_css,rewrite_javascript
	<span style="color: #adadad; font-style: italic;">#Cache/compress images. Couold also move the image to  HTML code (base64 encoded) if image size is small enough</span>
	ModPagespeedEnableFilters rewrite_images
	<span style="color: #adadad; font-style: italic;">#Add longer expires headers</span>
	ModPagespeedEnableFilters extend_cache
	<span style="color: #adadad; font-style: italic;">#Insert &quot;width&quot; and &quot;height&quot; attributes if not used</span>
	ModPagespeedEnableFilters insert_img_dimensions
	<span style="color: #adadad; font-style: italic;">#Remove HTML comments</span>
	ModPagespeedEnableFilters remove_comments
	<span style="color: #adadad; font-style: italic;"># Removes quotes around HTML attributes that are not lexically required</span>
	ModPagespeedEnableFilters remove_quotes
&nbsp;
	<span style="color: #adadad; font-style: italic;">#pagespeed enabled domain 1</span>
	ModPagespeedDomain tv.bartv.be
	<span style="color: #adadad; font-style: italic;">#Pagespeed enabled domain 2</span>
	ModPagespeedDomain cloudcast.bartv.be
	<span style="color: #adadad; font-style: italic;">#pagespeed enabled domain 3</span>
	ModPagespeedDomain notes.bartv.be
&nbsp;
	<span style="color: #adadad; font-style: italic;">#Maximum filesize cache</span>
	ModPagespeedFileCacheSizeKb          <span style="color: #ff0000;">10240</span>
	<span style="color: #adadad; font-style: italic;">#Interval to which cache is refreshed</span>
	ModPagespeedFileCacheCleanIntervalMs <span style="color: #ff0000;">3600000</span>
	ModPagespeedLRUCacheKbPerProcess     <span style="color: #ff0000;">1024</span>
	ModPagespeedLRUCacheByteLimit        <span style="color: #ff0000;">16384</span>
	<span style="color: #adadad; font-style: italic;">#Minimum allowed bytes in CSS before exporting to external CSS</span>
	ModPagespeedCssOutlineMinBytes       <span style="color: #ff0000;">1000</span>
	<span style="color: #adadad; font-style: italic;">#Minimum allowed bytes in JS before exporting to external JS</span>
	ModPagespeedJsOutlineMinBytes        <span style="color: #ff0000;">3000</span>
        <span style="color: #adadad; font-style: italic;">#Maximum allowed filesize for embedding images inline (base64)</span>
        ModPagespeedImgInlineMaxBytes        <span style="color: #ff0000;">2048</span>
&nbsp;
&lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;</pre></div></div>

<h3>Carefull with writing permissions</h3>
<p>On my webserver, I run every website under a different user account (e.g. mycoolwebsite.bartv.be is run by user &#8216;coolwebsite&#8217; or something). They all belong to the group &#8216;www-data&#8217;.<br />
Now one consequence of this is that the cache being written  by mod_pagespeed gets written by the user running the website. So be carefull with writing permissions in <strong>/var/mod_pagespeed/</strong></p>
<h2>Footnote</h2>
<p>Even though this article might suggest it. I&#8217;m in no way promoting quick and dirty development.<br />
You could think: to hell with it, I&#8217;ll just write whatever I want, mod_pagespeed will solve it for me. <strong>Don&#8217;t</strong></p>
<p>
mod_pagespeed is great, but in my eyes, it helps you find errors you might have missed. And it lets you use your development CSS/JS files without compressing them first.<br />
But don&#8217;t use it to clean up your mess!</p>
]]></content:encoded>
			<wfw:commentRss>http://notes.bartv.be/guide-to-googles-mod_apache/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mixcloud API</title>
		<link>http://notes.bartv.be/mixcloud-api/</link>
		<comments>http://notes.bartv.be/mixcloud-api/#comments</comments>
		<pubDate>Mon, 29 Nov 2010 15:28:14 +0000</pubDate>
		<dc:creator>bart</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[mixcloud]]></category>
		<category><![CDATA[music]]></category>

		<guid isPermaLink="false">http://notes.bartv.be/?p=66</guid>
		<description><![CDATA[TweetRecently, I came to the conclusion that the beautifull service of Mixcloud was missing a really cool feature: podcasting. They have som really cool artists posting music on there, and I enjoy listening to mixcloud sets every day at work. But there&#8217;s just no possibility for me to take these with me in my car [...]]]></description>
			<content:encoded><![CDATA[<div id="tweetbutton66" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fbit.ly%2FgbnBGM&amp;via=dotbart&amp;text=Mixcloud%20API&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fnotes.bartv.be%2Fmixcloud-api%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://notes.bartv.be/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p>Recently, I came to the conclusion that the beautifull service of <a href="http://www.mixcloud.com" target="_new" rel="nofollow">Mixcloud</a> was missing a really cool feature: podcasting.</p>
<p>They have som really cool artists posting music on there, and I enjoy listening to mixcloud sets every day at work. But there&#8217;s just no possibility for me to take these with me in my car (as in: on my iPod).</p>
<p>To fix this, I developed a small service called <a href="http://cloudcast.bartv.be" target="_new">CloudCast</a>. It was simple, just enter the username of your favorite artist on Mixcloud and you would be redirected to a page that gave an overview of this artist&#8217;s recent mixes, and gave you an RSS/Podcast link for your favorite music player.<br />
All was good, &#8230; for about 17 hours.</p>
<p>I got contacted by <a href="http://www.twitter.com/matclayton" target="_new">@matclayton</a> on Twitter the <a href="https://twitter.com/#!/matclayton/statuses/5215869751795712" target="_new">asking me to contact him.</a></p>
<p>
We had some email communication. But in the end it boiled down to this:<br />
Mixcloud has to pay artists royalties for every time a user listens to a mix. This is also why a mix is divided into tracks, so the respective artist is paid the respective amount. Whenever you download a track to your computer, there are 2 problems:</p>
<ul>
<li>they don&#8217;t know how many times you play it</li>
<li>just having the file on your computer violates copyrights</li>
</ul>
<p>So I had to close the website (which kind of sucks, it drove a lot of traffic to my site!)<br />
Mixcloud are soon to change the way their API works, so API-sniffing people like me can&#8217;t make cloudcast services that allow a user to download the MP3&#8242;s.<br />
So the problem should be solved soon anyway.
</p>
<p>However, knowledge is free. So I&#8217;m here to share what I&#8217;ve learn&#8217;t from their API.</p>
<h2>Step 1: getting the user&#8217;s mixes</h2>
<p>The URL you&#8217;re going to want to use is
<pre>http://api.mixcloud.com/[username]/cloudcasts/</pre>
<p>This gives you a JSON result. For every &#8216;Cast&#8217; they give you, they give you a <strong>slug</strong>. You&#8217;re going to use this slug.</p>
<p><strong>Tip:</strong> You can use the parameter &#8216;limit&#8217; to define how many results you want. (e.g. ?limit=50)</p>
<h2>Step 2: getting Cast information</h2>
<p>This one uses a different API I guess:
<pre>http://www.mixcloud.com/api/1/cloudcast/[username]/[slug].json</pre>
<p> Also returns JSON</p>
<p>This gives you, somewhere in the API a variable called <strike>&#8216;mp3_urls&#8217;</strike> &#8216;audio_formats&#8217;.<br />
<em>Jackpot!</em> I hear you think. And you&#8217;d be right. However Mixcloud gives you 4 url&#8217;s. They don&#8217;t always seem to work all 4. So keep in mind you want to check those URL&#8217;s for 404&#8242;s <img src='http://notes.bartv.be/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<h2>Step 3</h2>
<p>Enjoy API hacking</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Update: </strong>I am now thinking of developing an Android application for the same purpose. This &#8216;kind of&#8217; downloads the mixes to your Android device aswell. But if the kind people of Mixcloud could provide me with an API functionality so a developer could say: &#8220;I&#8217;m now listening to Mix A from artist XYZ&#8221;. That would solve all problems&#8230; I guess</p>
]]></content:encoded>
			<wfw:commentRss>http://notes.bartv.be/mixcloud-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SOLR server with basic authentication in Spring</title>
		<link>http://notes.bartv.be/solr-server-with-basic-authentication-in-spring/</link>
		<comments>http://notes.bartv.be/solr-server-with-basic-authentication-in-spring/#comments</comments>
		<pubDate>Tue, 05 Oct 2010 14:53:41 +0000</pubDate>
		<dc:creator>bart</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[httpclient]]></category>
		<category><![CDATA[solr]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://notes.bartv.be/?p=59</guid>
		<description><![CDATA[TweetAbout SOLR SOLR is a great search server, written under the Apache license. This means 2 things: it&#8217;s free and supported by a great community of experts! It&#8217;s important to know that SOLR consists of 2 parts: The solr server: a standalone Java application that handles data management and searching The solr web applicaton: provides [...]]]></description>
			<content:encoded><![CDATA[<div id="tweetbutton59" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fbit.ly%2FbVE44R&amp;via=dotbart&amp;text=SOLR%20server%20with%20basic%20authentication%20in%20Spring&amp;related=dotbart&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fnotes.bartv.be%2Fsolr-server-with-basic-authentication-in-spring%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://notes.bartv.be/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><h2>About SOLR</h2>
<p>
<a href="http://lucene.apache.org/solr/">SOLR</a> is a great search server, written under the Apache license.<br />
This means 2 things: it&#8217;s free and supported by a great community of experts!
</p>
<p>
It&#8217;s important to know that SOLR consists of 2 parts:</p>
<ul>
<li><strong>The solr server:</strong> a standalone Java application that handles data management and searching</li>
<li><strong>The solr web applicaton:</strong> provides web services and handles requests. Deploy this to Tomcat, or use the integrated Jetty
</ul>
<p>
Also, solr provides a Java interface called <a href="http://wiki.apache.org/solr/Solrj">SOLRj</a>.<br />
SOLRj provides 2 ways of connecting to your SOLR server:</p>
<ul>
<li><a href="http://lucene.apache.org/solr/api/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.html">EmbeddedSolrServer</a> connects directly to your SOLR server core and omits the web application</li>
<li><a href="http://lucene.apache.org/solr/api/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.html">CommonsHttpSolrServer</a> connects to the SOLR web app
</ul>
<p>Now I hear you thinking: why would I go via the Web App when I can connect directly to the core?<br />
The answer is simple: <strong>distributed servers</strong>. Imagine your web application is divided among multiple servers in order to balance the load, you can&#8217;t connect to the SOLRCore, unless you use multiple solr instances (which I don&#8217;t at the moment).
</p>
<h2>The Problem</h2>
<p>
So we&#8217;re using the SOLR web app on 1 server, and we use it&#8217;s webservices.<br />
However, we don&#8217;t really want to leave it nice and open so any scriptkiddie can just connect to <a href="http://yourprettysolrserver.com/solr/admin/">http://yourprettysolrserver.com/solr/<strong>admin/</strong></a>. So we use Basic HTTP authentication (I know, still not very secure. But the communication will only happen between the 2 virtual servers, so no chance of a <strong>Man in the Middle attack</strong>).<br />
On notes how to secure your SOLR via basic auth, visit the <a href="http://wiki.apache.org/solr/SolrSecurity">SolrSecurity Wiki page</a>.
</p>
<h2>The Solution</h2>
<p>SolrJ uses Apache&#8217;s<br />
So doing it in Java should go in a jiffy(<a href="http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/examples/BasicAuthenticationExample.java?view=markup>HttpClient Basic Auth example </a>)</p>
<p>Doing it in Spring provides a bit of an issue tho: Spring uses its own implementation of a HttpClient (<a href="http://static.springsource.org/spring/docs/2.0.x/reference/remoting.html#remoting-httpinvoker">as described here</a>).</p>
<p>My solution was a bit quick, and maybe a bit dirty, but it works!<br />
I made a subclass of HttpClient:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BasicAuthHttpClient <span style="color: #000000; font-weight: bold;">extends</span> HttpClient <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> BasicAuthHttpClient<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> BasicAuthHttpClient<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> username, <span style="color: #003399;">String</span> pass<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		Credentials creds <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> UsernamePasswordCredentials<span style="color: #009900;">&#40;</span>username,pass<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getState</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setCredentials</span><span style="color: #009900;">&#40;</span>AuthScope.<span style="color: #006633;">ANY</span>, creds<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getParams</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setAuthenticationPreemptive</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>There&#8217;s a constructor that simply takes a username and password as argument.<br />
In my ApplicationContext, I defined the following:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;solrHttpClient&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.example.system.utility.BasicAuthHttpClient&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${solrserver_user}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${solrserver_pass}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;httpSolrServer&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.apache.solr.client.solrj.impl.CommonsHttpSolrServer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${solrserver_path}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;solrHttpClient&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Works like a charm here! And should be thread safe.<br />
Hope it helps somebody</p>
]]></content:encoded>
			<wfw:commentRss>http://notes.bartv.be/solr-server-with-basic-authentication-in-spring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

