<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Frederik Vig - ASP.NET developer</title>
	
	<link>http://www.frederikvig.com</link>
	<description />
	<lastBuildDate>Sun, 13 May 2012 11:54:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/frederikvig" /><feedburner:info uri="frederikvig" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Strongly typed access to your page data objects inside ItemTemplate</title>
		<link>http://feedproxy.google.com/~r/frederikvig/~3/vKan-VwS068/</link>
		<comments>http://www.frederikvig.com/2012/05/strongly-typed-access-to-your-page-data-objects-inside-itemtemplate/#comments</comments>
		<pubDate>Thu, 10 May 2012 12:19:56 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[EPiServer]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1778</guid>
		<description><![CDATA[Here&#8217;s a little quick tip on how I usually set up my code to get strongly typed access to my page types inside Repeaters, ListViews, PageLists etc. I use PageTypeBuilder in all my projects so I&#8217;m going to use it in the examples here as well, but you could just use the regular PageData objects ...]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little quick tip on how I usually set up my code to get strongly typed access to my page types inside Repeaters, ListViews, PageLists etc.</p>
<p>I use PageTypeBuilder in all my projects so I&#8217;m going to use it in the examples here as well, but you could just use the regular PageData objects instead (with a little more code).</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Repeater runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;rptNews&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>HeaderTemplate<span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>div <span style="color: #6666cc; font-weight: bold;">class</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;entries&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>HeaderTemplate<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>ItemTemplate<span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;%</span><span style="color: #008080;"># SetItem(Container.DataItem) %&gt;</span>
	    <span style="color: #008000;">&lt;</span>div <span style="color: #6666cc; font-weight: bold;">class</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;entry&quot;</span><span style="color: #008000;">&gt;</span>
	    <span style="color: #008000;">&lt;</span>a href<span style="color: #008000;">=</span><span style="color: #666666;">&quot;&lt;%# NewsPage.LinkURL %&gt;&quot;</span><span style="color: #008000;">&gt;</span>
		<span style="color: #008000;">&lt;</span>img src<span style="color: #008000;">=</span><span style="color: #666666;">&quot;&lt;%# NewsPage.ListImage %&gt;&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> visible<span style="color: #008000;">=</span><span style="color: #666666;">&quot;&lt;%# NewsPage.ListImage.IsNotNullOrEmpty() %&gt;&quot;</span> <span style="color: #008000;">/&gt;</span>
		<span style="color: #008000;">&lt;</span>h2<span style="color: #008000;">&gt;&lt;%</span><span style="color: #008080;"># NewsPage.Heading %&gt;&lt;/h2&gt;</span>
	    <span style="color: #008000;">&lt;/</span>a<span style="color: #008000;">&gt;</span>
	    <span style="color: #008000;">&lt;</span>div <span style="color: #6666cc; font-weight: bold;">class</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;date&quot;</span><span style="color: #008000;">&gt;</span>
		<span style="color: #008000;">&lt;%</span><span style="color: #008080;"># NewsItem.StartPublish.ToString(&quot;dd.MM.yyyy&quot;) %&gt;&lt;/div&gt;</span>
	    <span style="color: #008000;">&lt;/</span>div<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>ItemTemplate<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>FooterTemplate<span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;/</span>div<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>FooterTemplate<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>asp<span style="color: #008000;">:</span>Repeater<span style="color: #008000;">&gt;</span></pre>
</div>
</div>
<p>The thing to note here is that I&#8217;m calling the method SetItem(), which sets the current news page for me.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">string</span> SetItem<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> dataItem<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">NewsPage</span> <span style="color: #008000;">=</span> dataItem <span style="color: #0600FF; font-weight: bold;">as</span> StandardPage<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<p>NewsPage is just a auto property of type StandardPage.</p>
<p>Update: 13.05.2012</p>
<p>Thanks to <a href="http://www.frederikvig.com/2012/05/strongly-typed-access-to-your-page-data-objects-inside-itemtemplate/#comment-8013">Jon&#8217;s comment</a>, we can simplify this code even more. Instead of using the SetItem method we can use the GetDataItem() method from the Page class.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> StandardPage NewsPage <span style="color: #008000;">&#123;</span> get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> Page<span style="color: #008000;">.</span><span style="color: #0000FF;">GetDataItem</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> StandardPage<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<p>This gives me strongly typed access to my objects. In ASP.NET 4.5 this will be even simpler since strongly typed access (model binding) will be built into controls like the Repeater, take a look at <a href="http://weblogs.asp.net/scottgu/archive/2011/09/06/web-forms-model-binding-part-1-selecting-data-asp-net-vnext-series.aspx">Scott Guthrie&#8217;s post</a> if you&#8217;re curious about ASP.NET 4.5.<strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/08/add-class-to-body-element-with-asp-net-web-forms-and-master-pages/" rel="bookmark" title="August 27, 2009">Add class attribute to body element with ASP.NET web forms and Master Pages</a></li>
<li><a href="http://www.frederikvig.com/2010/05/creating-a-contact-form-with-asp-net-mvc/" rel="bookmark" title="May 13, 2010">Creating a contact form with ASP.NET MVC</a></li>
<li><a href="http://www.frederikvig.com/2009/10/episerver-findpageswithcriteria-and-findallpageswithcriteria/" rel="bookmark" title="October 21, 2009">EPiServer FindPagesWithCriteria and FindAllPagesWithCriteria</a></li>
<li><a href="http://www.frederikvig.com/2010/01/a-developers-guide-to-pagetypebuilder/" rel="bookmark" title="January 15, 2010">A developer&#8217;s guide to Page Type Builder</a></li>
<li><a href="http://www.frederikvig.com/2009/08/adding-css-and-javascript-files-dynamically-to-your-asp-net-page/" rel="bookmark" title="August 15, 2009">Adding CSS and JavaScript files dynamically to your ASP.NET page</a></li>
</ul>
<p><!-- Similar Posts took 18.683 ms --></p>
<img src="http://feeds.feedburner.com/~r/frederikvig/~4/vKan-VwS068" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2012/05/strongly-typed-access-to-your-page-data-objects-inside-itemtemplate/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://www.frederikvig.com/2012/05/strongly-typed-access-to-your-page-data-objects-inside-itemtemplate/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=strongly-typed-access-to-your-page-data-objects-inside-itemtemplate</feedburner:origLink></item>
		<item>
		<title>Manually upgrading the database from EPiServer Commerce R2 SP1 to EPiServer Commerce R2 SP2</title>
		<link>http://feedproxy.google.com/~r/frederikvig/~3/qMsvS6DwKYI/</link>
		<comments>http://www.frederikvig.com/2012/05/manually-upgrading-the-database-from-episerver-commerce-r2-sp1-to-episerver-commerce-r2-sp2/#comments</comments>
		<pubDate>Wed, 09 May 2012 10:14:23 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[EPiServer Commerce]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1776</guid>
		<description><![CDATA[Here&#8217;s an overview over the SQL scripts you need to execute to manually upgrade your sites commerce database from EPiServer Commerce R2 SP1 to EPiServer Commerce R2 SP2. C:\Program Files (x86)\EPiServer\CMS\6.1.379.0\Install\Modules\EPiServer Commerce 1.1.2.62\Setup\cms_db_upgrade.sql C:\Program Files (x86)\EPiServer\CMS\6.1.379.0\Install\Modules\EPiServer Commerce 1.1.2.62\MediachaseECF\Data\DeploymentPackage\SqlScripts\Update\ecf_db_ApplicationSystem_update.sql C:\Program Files (x86)\EPiServer\CMS\6.1.379.0\Install\Modules\EPiServer Commerce 1.1.2.62\MediachaseECF\Data\DeploymentPackage\SqlScripts\Update\ecf_db_BusinessFoundation_update.sql C:\Program Files (x86)\EPiServer\CMS\6.1.379.0\Install\Modules\EPiServer Commerce 1.1.2.62\MediachaseECF\Data\DeploymentPackage\SqlScripts\Update\ecf_db_CatalogSystem_update.sql C:\Program Files (x86)\EPiServer\CMS\6.1.379.0\Install\Modules\EPiServer Commerce 1.1.2.62\MediachaseECF\Data\DeploymentPackage\SqlScripts\Update\ecf_db_MarketingSystem_update.sql C:\Program Files ...]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an overview over the SQL scripts you need to execute to manually upgrade your sites commerce database from EPiServer Commerce R2 SP1 to EPiServer Commerce R2 SP2.</p>
<ol>
<li>C:\Program Files (x86)\EPiServer\CMS\6.1.379.0\Install\Modules\EPiServer Commerce 1.1.2.62\Setup\cms_db_upgrade.sql</li>
<li>C:\Program Files (x86)\EPiServer\CMS\6.1.379.0\Install\Modules\EPiServer Commerce 1.1.2.62\MediachaseECF\Data\DeploymentPackage\SqlScripts\Update\ecf_db_ApplicationSystem_update.sql</li>
<li>C:\Program Files (x86)\EPiServer\CMS\6.1.379.0\Install\Modules\EPiServer Commerce 1.1.2.62\MediachaseECF\Data\DeploymentPackage\SqlScripts\Update\ecf_db_BusinessFoundation_update.sql</li>
<li>C:\Program Files (x86)\EPiServer\CMS\6.1.379.0\Install\Modules\EPiServer Commerce 1.1.2.62\MediachaseECF\Data\DeploymentPackage\SqlScripts\Update\ecf_db_CatalogSystem_update.sql</li>
<li>C:\Program Files (x86)\EPiServer\CMS\6.1.379.0\Install\Modules\EPiServer Commerce 1.1.2.62\MediachaseECF\Data\DeploymentPackage\SqlScripts\Update\ecf_db_MarketingSystem_update.sql</li>
<li>C:\Program Files (x86)\EPiServer\CMS\6.1.379.0\Install\Modules\EPiServer Commerce 1.1.2.62\MediachaseECF\Data\DeploymentPackage\SqlScripts\Update\ecf_db_MetaDataSystem_update.sql</li>
<li>C:\Program Files (x86)\EPiServer\CMS\6.1.379.0\Install\Modules\EPiServer Commerce 1.1.2.62\MediachaseECF\Data\DeploymentPackage\SqlScripts\Update\ecf_db_OrderSystem_update.sql</li>
<li>C:\Program Files (x86)\EPiServer\CMS\6.1.379.0\Install\Modules\EPiServer Commerce 1.1.2.62\MediachaseECF\Data\DeploymentPackage\SqlScripts\Update\ecf_db_Reporting_update.sql</li>
<li>C:\Program Files (x86)\EPiServer\CMS\6.1.379.0\Install\Modules\EPiServer Commerce 1.1.2.62\MediachaseECF\Data\DeploymentPackage\SqlScripts\Update\ecf_db_SecuritySystem_update.sql</li>
<li>C:\Program Files (x86)\EPiServer\CMS\6.1.379.0\Install\Modules\EPiServer Commerce 1.1.2.62\MediachaseECF\Data\DeploymentPackage\SqlScripts\Update\ecf_db_Users_upgrade.sql</li>
<li>C:\Program Files (x86)\EPiServer\CMS\6.1.379.0\Install\Modules\EPiServer Commerce 1.1.2.62\Setup\ecf_products_ProductsQuery.sql</li>
</ol>
<p>Here&#8217;s the whole tech-note: <a href="http://world.episerver.com/Documentation/Items/Installation-Instructions/EPiServer-Commerce/Upgrading-EPiServer-Commerce-from-version-1-R2-SP1-to-1-R2-SP2-/">Upgrading EPiServer Commerce from version 1 R2 SP1 to 1 R2 SP2</a>.</p>
<p>What I usually do is upgrade locally, check everything into source control, deploy to the different dev/test environments, download and install the new version from <a href="http://world.episerver.com">EPiServer World</a>, and then manually upgrade the databases. This means I only have to step through the upgrade wizard once. I can even automatically execute the upgrade scripts in my deployment process so I don&#8217;t have to do anything manually.<strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2011/06/episerver-mail-5-r2-installation-problem/" rel="bookmark" title="June 2, 2011">EPiServer Mail 5 R2 Installation problem</a></li>
<li><a href="http://www.frederikvig.com/2011/10/installing-episerver-live-monitor-on-iis-7-running-net-4/" rel="bookmark" title="October 7, 2011">Installing EPiServer Live Monitor on IIS 7 running .NET 4</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-1-setting-up-the-development-environment-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 4, 2009">Part 1: Setting up the development environment &#8211; Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2011/10/faster-episerver-sites-client-side-performance/" rel="bookmark" title="October 9, 2011">Faster EPiServer sites &#8211; client side performance</a></li>
<li><a href="http://www.frederikvig.com/2010/02/visual-studio-2010-episerver-snippets/" rel="bookmark" title="February 11, 2010">Visual Studio 2010 EPiServer Snippets</a></li>
</ul>
<p><!-- Similar Posts took 45.708 ms --></p>
<img src="http://feeds.feedburner.com/~r/frederikvig/~4/qMsvS6DwKYI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2012/05/manually-upgrading-the-database-from-episerver-commerce-r2-sp1-to-episerver-commerce-r2-sp2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.frederikvig.com/2012/05/manually-upgrading-the-database-from-episerver-commerce-r2-sp1-to-episerver-commerce-r2-sp2/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=manually-upgrading-the-database-from-episerver-commerce-r2-sp1-to-episerver-commerce-r2-sp2</feedburner:origLink></item>
		<item>
		<title>Faster EPiServer sites – image optimization</title>
		<link>http://feedproxy.google.com/~r/frederikvig/~3/_UOFwbo83hs/</link>
		<comments>http://www.frederikvig.com/2012/05/faster-episerver-sites-image-optimization/#comments</comments>
		<pubDate>Sun, 06 May 2012 08:38:08 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1767</guid>
		<description><![CDATA[Continuing on our goal to get the fastest EPiServer site possible, let&#8217;s take on images, specifically images that editors upload. In my experience even after launching a site that scores almost a complete score with YSlow, Page Speed etc, after having editors work on the site for a couple of months the site usually slows ...]]></description>
			<content:encoded><![CDATA[<p>Continuing on our goal to get the <a href="http://www.frederikvig.com/2011/10/faster-episerver-sites-client-side-performance/">fastest EPiServer site possible</a>, let&#8217;s take on images, specifically images that editors upload. In my experience even after launching a site that scores almost a complete score with <a href="http://yslow.org/">YSlow</a>, <a href="https://developers.google.com/speed/pagespeed/">Page Speed</a> etc, after having editors work on the site for a couple of months the site usually slows down quite a bit. One of the main reasons I&#8217;ve found for this is that not all editors think about optimizing images for the web.</p>
<p>To make it easier for our editors <a href="http://geta.no">Geta</a> as developed a simple tool that runs as a scheduled job on your EPiServer site, it runs has often has you need it to and goes through all your sites images and compresses them as much as possible without loosing any quality.</p>
<p>The service that we&#8217;re using is <a href="http://www.smushit.com/ysmush.it/">Smush.it</a> run by Yahoo! and the people behind <a href="http://yslow.org/">YSlow</a>. We&#8217;ve run this on various live sites and the result is quite good, in a case where the site had professional editors (they had their own production partner), we saved around 30% of each image, and I know for a fact that the editors always used Photoshop and save for web. Imagine how much this will save for editors that don&#8217;t think about this?</p>
<h3>Installation</h3>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;">Install<span style="color: #008000;">-</span>Package Geta<span style="color: #008000;">.</span><span style="color: #0000FF;">ImageOptimization</span></pre>
</div>
</div>
<p>You can get everything you need from <a href="http://nuget.episerver.com/en/OtherPages/Package/?packageId=Geta.ImageOptimization">NuGet</a>. Note that you need to use a public URL and that there are some configuration settings, web.config:</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;section</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ImageOptimizationSettings&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Geta.ImageOptimization.Configuration.ImageOptimizationSettings, Geta.ImageOptimization&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ImageOptimizationSettings</span> <span style="color: #000066;">siteUrl</span>=<span style="color: #ff0000;">&quot;http://abk.geta.no&quot;</span> <span style="color: #000066;">virtualNames</span>=<span style="color: #ff0000;">&quot;Page Files,Global Files,Documents&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre>
</div>
</div>
<p>If nothing is specified it will scan through all VPPs and use the siteUrl from episerver.config.</p>
<h3>Source code</h3>
<p>All code is available as open source in <a href="https://bitbucket.org/GetaAS/opensource/src">Geta&#8217;s open source repository</a> up on <a href="https://bitbucket.org">Bitbucket</a>.</p>
<h3>Running it</h3>
<p>After the installation you&#8217;ll have a new scheduled job called &#8220;Geta Image Optimization&#8221;, you can either run it manually or set it up to run once a week or similar. The first time you run it, depending in the size of the site, it can take quite a lot of time. The Smush.it service can be a little slow, but it shouldn&#8217;t matter because it will run in a different windows service than your site and use very little resources.</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/2012/05/geta-image-optimization-scheduled-job.png" />
</p>
<p>The next time you run the job it will only compress the new images and leave the images that it already has compressed. It should go quite a lot faster after a couple of runs.</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/2012/05/geta-image-optimization-scheduled-job-running.png" />
</p>
<p>(Note that this is for Alloy Tech demo, most live sites I know have quite a lot more images <img src='http://www.frederikvig.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )</p>
<h3>What about local images?</h3>
<p>For images in local folders (typical CSS background images), we usually use the <a href="http://visualstudiogallery.msdn.microsoft.com/a56eddd3-d79b-48ac-8c8f-2db06ade77c3">Visual Studio Image Optimizer extension</a>, after installing it you can right-click any folder or image in Visual Studio and optimize the images.</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/2012/05/visual-studio-optimize-images.png" />
</p>
<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2011/10/installing-episerver-live-monitor-on-iis-7-running-net-4/" rel="bookmark" title="October 7, 2011">Installing EPiServer Live Monitor on IIS 7 running .NET 4</a></li>
<li><a href="http://www.frederikvig.com/2010/09/introducing-oembed-for-episerver/" rel="bookmark" title="September 25, 2010">Introducing oEmbed for EPiServer</a></li>
<li><a href="http://www.frederikvig.com/2012/02/open-source-mobilepack-version-1-0/" rel="bookmark" title="February 8, 2012">Open Source MobilePack version 1.0</a></li>
<li><a href="http://www.frederikvig.com/2010/11/removing-http-headers-for-asp-net-sites/" rel="bookmark" title="November 26, 2010">Removing HTTP Headers for ASP.NET sites</a></li>
<li><a href="http://www.frederikvig.com/2011/11/geta-oembed-version-1-2-is-out/" rel="bookmark" title="November 19, 2011">Geta.oEmbed version 1.2 is out</a></li>
</ul>
<p><!-- Similar Posts took 12.995 ms --></p>
<img src="http://feeds.feedburner.com/~r/frederikvig/~4/_UOFwbo83hs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2012/05/faster-episerver-sites-image-optimization/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.frederikvig.com/2012/05/faster-episerver-sites-image-optimization/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=faster-episerver-sites-image-optimization</feedburner:origLink></item>
		<item>
		<title>Using the ASP.NET Web API Framework with EPiServer</title>
		<link>http://feedproxy.google.com/~r/frederikvig/~3/36xpvrBIgE4/</link>
		<comments>http://www.frederikvig.com/2012/02/using-the-asp-net-web-api-framework-with-episerver/#comments</comments>
		<pubDate>Thu, 23 Feb 2012 20:35:54 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[ASP.NET Web API]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1752</guid>
		<description><![CDATA[With the ASP.NET Web API framework we can easily build restful API&#8217;s that allow us to expose our data to a whole bunch of different clients, everything from rich JavaScript applications to Flash or mobile apps. The cool thing about the Web API framework is that you don&#8217;t need ASP.NET MVC 4 to run it, ...]]></description>
			<content:encoded><![CDATA[<p>With the <a href="http://www.asp.net/web-api">ASP.NET Web API framework</a> we can easily build restful API&#8217;s that allow us to expose our data to a whole bunch of different clients, everything from rich JavaScript applications to Flash or mobile apps.</p>
<p>The cool thing about the Web API framework is that you don&#8217;t need ASP.NET MVC 4 to run it, we can easily get everything we need with NuGet and then deploy it to our server without having to install anything extra on the server.</p>
<h3>Getting started</h3>
<p>Our EPiServer site needs to run .NET 4 for this to work, for this tutorial I installed a local copy of the AlloyTech sample site. I then upgraded it to use .NET 4 and installed the ASP.NET Web API through <a href="http://nuget.org/">NuGet</a>.</p>
<p><a href="http://www.frederikvig.com/wp-content/uploads/2012/02/nuget-webapi-install.png"><img src="http://www.frederikvig.com/wp-content/uploads/2012/02/nuget-webapi-install.png" alt="" width="702" height="184" /></a></p>
<p>This will download and add everything we need for running ASP.NET Web API on our site.</p>
<p>We now need to setup the routing rules in the Application_Start method in global.asax. After adding the routing rules my global.asax looks like this.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.Http</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.Routing</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.UI</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.UI.WebControls</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">EPiServer.Core</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">EPiServer.Globalization</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">EPiServer.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">EPiServer.XForms.WebControls</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Label </span><span style="color: #008000;">=</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Web</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UI</span><span style="color: #008000;">.</span><span style="color: #0000FF;">WebControls</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Label</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">RouteParameter </span><span style="color: #008000;">=</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Web</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Http</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RouteParameter</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> EPiServer<span style="color: #008000;">.</span><span style="color: #0000FF;">Templates</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> Global <span style="color: #008000;">:</span> EPiServer<span style="color: #008000;">.</span><span style="color: #0000FF;">Global</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> Application_Start<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">Object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
                    XFormControl<span style="color: #008000;">.</span><span style="color: #0000FF;">ControlSetup</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> EventHandler<span style="color: #008000;">&#40;</span>XForm_ControlSetup<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    RegisterRoutes<span style="color: #008000;">&#40;</span>RouteTable<span style="color: #008000;">.</span><span style="color: #0000FF;">Routes</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> RegisterRoutes<span style="color: #008000;">&#40;</span>RouteCollection routes<span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    routes<span style="color: #008000;">.</span><span style="color: #0000FF;">MapHttpRoute</span><span style="color: #008000;">&#40;</span>
                       name<span style="color: #008000;">:</span> <span style="color: #666666;">&quot;ActionApi&quot;</span>,
                       routeTemplate<span style="color: #008000;">:</span> <span style="color: #666666;">&quot;api/{controller}/{action}/{id}&quot;</span>,
                       defaults<span style="color: #008000;">:</span> <span style="color: #008000;">new</span> <span style="color: #008000;">&#123;</span> id <span style="color: #008000;">=</span> RouteParameter<span style="color: #008000;">.</span><span style="color: #0000FF;">Optional</span> <span style="color: #008000;">&#125;</span>
                    <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
&nbsp;
                <span style="color: #008080;">#region Global XForm Events</span>
                <span style="color: #008000;">...</span>
                <span style="color: #008080;">#endregion</span>
        <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<p>For more information on the routing table take a look at this article: <a href="http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-in-aspnet-web-api">Routing in ASP.NET Web API</a>.</p>
<h3>Creating the API</h3>
<p>Create a new class and give it the name PagesController, place it in a folder called Api. Our controller is going to inherit from the abstract base class ApiController.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.Http</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> EPiServer<span style="color: #008000;">.</span><span style="color: #0000FF;">Api</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> PagesController <span style="color: #008000;">:</span> ApiController
    <span style="color: #008000;">&#123;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<p>We are going to use the Pages API to expose EPiServer PageData to the public. We can then easily use this content in different channels and applications.</p>
<p>The URLs for our API are going to look something like this: /api/pages/get/{id}, /api/pages/getchildren/{id}.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.Http</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">EPiServer.Core</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">EPiServer.Mapping</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">EPiServer.Security</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">EPiServer.ViewModels</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> EPiServer<span style="color: #008000;">.</span><span style="color: #0000FF;">Api</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> PagesController <span style="color: #008000;">:</span> ApiController
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> PageDataView Get<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> id<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            PageData page <span style="color: #008000;">=</span> DataFactory<span style="color: #008000;">.</span><span style="color: #0000FF;">Instance</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetPage</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> PageReference<span style="color: #008000;">&#40;</span>id<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>page <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> HttpResponseException<span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Net</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">HttpStatusCode</span><span style="color: #008000;">.</span><span style="color: #0000FF;">NotFound</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>page<span style="color: #008000;">.</span><span style="color: #0000FF;">CheckPublishedStatus</span><span style="color: #008000;">&#40;</span>PagePublishedStatus<span style="color: #008000;">.</span><span style="color: #0000FF;">Published</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span> <span style="color: #008000;">!</span>page<span style="color: #008000;">.</span><span style="color: #0000FF;">QueryDistinctAccess</span><span style="color: #008000;">&#40;</span>AccessLevel<span style="color: #008000;">.</span><span style="color: #0000FF;">Read</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> HttpResponseException<span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Net</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">HttpStatusCode</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Forbidden</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> page<span style="color: #008000;">.</span><span style="color: #0000FF;">ConvertToPageDataView</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> IEnumerable<span style="color: #008000;">&lt;</span>PageDataView<span style="color: #008000;">&gt;</span> GetChildren<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> id<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            var pages <span style="color: #008000;">=</span> DataFactory<span style="color: #008000;">.</span><span style="color: #0000FF;">Instance</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetChildren</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> PageReference<span style="color: #008000;">&#40;</span>id<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>pages <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> HttpResponseException<span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Net</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">HttpStatusCode</span><span style="color: #008000;">.</span><span style="color: #0000FF;">NotFound</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            Filters<span style="color: #008000;">.</span><span style="color: #0000FF;">FilterForVisitor</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Filter</span><span style="color: #008000;">&#40;</span>pages<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>pages<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> HttpResponseException<span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Net</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">HttpStatusCode</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Forbidden</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> pages<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Select</span><span style="color: #008000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> p<span style="color: #008000;">.</span><span style="color: #0000FF;">ConvertToPageDataView</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<p>The content can of course also come from dynamic data store or any other place for that matter. Note that I created a view model or data transfer object to send to the client. The main reason is that you&#8217;ll get a serialization exception if you try and use a PageData object.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> EPiServer<span style="color: #008000;">.</span><span style="color: #0000FF;">ViewModels</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> PageDataView
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Heading <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> LinkUrl <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> MainIntro <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> MainBody <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> DateTime StartPublish <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Author <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">EPiServer.Core</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">EPiServer.ViewModels</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> EPiServer<span style="color: #008000;">.</span><span style="color: #0000FF;">Mapping</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">class</span> PagesMapper
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> PageDataView ConvertToPageDataView<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData pageData<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> PageDataView
                       <span style="color: #008000;">&#123;</span>
                           Author <span style="color: #008000;">=</span> pageData<span style="color: #008000;">.</span><span style="color: #0000FF;">CreatedBy</span>,
                           StartPublish <span style="color: #008000;">=</span> pageData<span style="color: #008000;">.</span><span style="color: #0000FF;">StartPublish</span>,
                           MainBody <span style="color: #008000;">=</span> pageData<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;MainBody&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> <span style="color: #6666cc; font-weight: bold;">string</span> <span style="color: #008000;">??</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span>,
                           MainIntro <span style="color: #008000;">=</span> pageData<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;MainIntro&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> <span style="color: #6666cc; font-weight: bold;">string</span> <span style="color: #008000;">??</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span>,
                           Heading <span style="color: #008000;">=</span> pageData<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;Heading&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> <span style="color: #6666cc; font-weight: bold;">string</span> <span style="color: #008000;">??</span> pageData<span style="color: #008000;">.</span><span style="color: #0000FF;">PageName</span>,
                           LinkUrl <span style="color: #008000;">=</span> pageData<span style="color: #008000;">.</span><span style="color: #0000FF;">LinkURL</span>
                       <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<p>Just some very simple mapper code here.</p>
<h3>Consuming the API</h3>
<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;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'loadingIndicator'</span>&gt;</span>Loading...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> data-bind<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;foreach: listItems&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
          <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> data-bind<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;attr: { href: LinkUrl }, text: Heading&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
          <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> data-bind<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text: StartPublish&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></pre>
</div>
</div>
<div class="wp_syntax">
<div class="code">
<pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://knockoutjs.com/js/knockout-2.0.0.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.loadingIndicator&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ajaxStart</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: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</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: #009900;">&#41;</span>.<span style="color: #660066;">ajaxComplete</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: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        $.<span style="color: #660066;">getJSON</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/api/pages/getchildren/41'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            viewModel.<span style="color: #660066;">listItems</span><span style="color: #009900;">&#40;</span>data<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>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> viewModel <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
            listItems<span style="color: #339933;">:</span> ko.<span style="color: #660066;">observableArray</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        ko.<span style="color: #660066;">applyBindings</span><span style="color: #009900;">&#40;</span>viewModel<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre>
</div>
</div>
<p>I&#8217;m using the <a href="http://knockoutjs.com/">Knockout JavaScript library</a> for populating the list and jQuery for getting the data from the API. This will display a loading message to the user and then populate the list with the data it gets back.</p>
<p><a href="http://www.frederikvig.com/wp-content/uploads/2012/02/list-view.png"><img src="http://www.frederikvig.com/wp-content/uploads/2012/02/list-view.png" alt="" width="454" height="255" /></a></p>
<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/11/removing-duplicates-from-a-pagedatacollection/" rel="bookmark" title="November 27, 2009">Removing duplicates from a PageDataCollection</a></li>
<li><a href="http://www.frederikvig.com/2009/06/episerver-filter-part-2/" rel="bookmark" title="June 28, 2009">EPiServer filter – part 2: create your own filter</a></li>
<li><a href="http://www.frederikvig.com/2009/12/extending-pagedata-with-some-cool-html-helpers/" rel="bookmark" title="December 8, 2009">Extending PageData with some cool Html Helpers</a></li>
<li><a href="http://www.frederikvig.com/2010/04/detecting-ajax-requests-on-the-server/" rel="bookmark" title="April 6, 2010">Detecting Ajax requests on the server</a></li>
<li><a href="http://www.frederikvig.com/2009/10/episerver-findpageswithcriteria-and-findallpageswithcriteria/" rel="bookmark" title="October 21, 2009">EPiServer FindPagesWithCriteria and FindAllPagesWithCriteria</a></li>
</ul>
<p><!-- Similar Posts took 49.685 ms --></p>
<img src="http://feeds.feedburner.com/~r/frederikvig/~4/36xpvrBIgE4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2012/02/using-the-asp-net-web-api-framework-with-episerver/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.frederikvig.com/2012/02/using-the-asp-net-web-api-framework-with-episerver/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=using-the-asp-net-web-api-framework-with-episerver</feedburner:origLink></item>
		<item>
		<title>Open Source MobilePack version 1.0</title>
		<link>http://feedproxy.google.com/~r/frederikvig/~3/XP5GkJbGTOI/</link>
		<comments>http://www.frederikvig.com/2012/02/open-source-mobilepack-version-1-0/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 22:52:00 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[mobilepack]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1726</guid>
		<description><![CDATA[I&#8217;m proud to announce that MobilePack is now in version 1.0 (stable). The team (@athraen, @jacobkhan and me) have been hard at work fixing bugs and adding new features for this release. New features/bug fixes Storing resized images for 7 days (default) in VPP for faster access Added ability to disable server image resizing Offline ...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m proud to announce that MobilePack is now in version 1.0 (stable). The team (<a href="http://twitter.com/#!/athraen">@athraen</a>, <a href="http://twitter.com/#!/jacobkhan">@jacobkhan</a> and <a href="http://twitter.com/#!/frederikvig">me</a>) have been hard at work fixing bugs and adding new features for this release.</p>
<h3>New features/bug fixes</h3>
<ul>
<li>Storing resized images for 7 days (default) in VPP for faster access</li>
<li>Added ability to disable server image resizing</li>
<li>Offline Manifest for using the site offline</li>
<li>Ability to have different redirects for different language versions of a page</li>
<li>Ability to turn off server-side image resizing</li>
<li>Now running jQuery Mobile 1.0.1</li>
<li>Switching between normal/mobile and mobile/normal site now works for sub-domains as well</li>
<li>Better language support for Google Maps location page type</li>
<li>Not trying to resize images the user does not have access to</li>
<li>Turned off all HTTP caching of resized images to avoid proxies storing and serving the same resized image to multiple devices running different resolutions</li>
<li>Refactored and cleaned up code base</li>
<li>Refactored Google Maps property as NuGet package</li>
<li>Easier installation and setup on new and existing sites</li>
</ul>
<h3>Installation</h3>
<ul>
<li>In visual studio, from the EPiServer NuGet Feed (remember to manually import the pagetypes from ‘/Setup’ afterwards)</li>
<li>By downloading the EPiServer Module from Codeplex and using EPiServer Deployment Center (‘Install Module’)</li>
<li>By fetching the source code directly from codeplex and compiling it yourself.</li>
</ul>
<p>Hope you enjoy it, and as always we welcome public feedback either on <a href="http://world.episerver.com">EPiServer World</a> or <a href="http://mobilepack.codeplex.com/">MobilePack on Codeplex</a>.<strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2011/03/links-for-episerver-developers-2/" rel="bookmark" title="March 12, 2011">Links for EPiServer Developers &#8211; #2</a></li>
<li><a href="http://www.frederikvig.com/2012/05/faster-episerver-sites-image-optimization/" rel="bookmark" title="May 6, 2012">Faster EPiServer sites &#8211; image optimization</a></li>
<li><a href="http://www.frederikvig.com/2009/10/creating-a-mobile-version-of-a-web-site/" rel="bookmark" title="October 4, 2009">Creating a mobile version of a web site</a></li>
<li><a href="http://www.frederikvig.com/2010/04/backup-plan-when-loading-the-jquery-library-from-cdn/" rel="bookmark" title="April 20, 2010">Backup plan when loading the jQuery library from CDN</a></li>
<li><a href="http://www.frederikvig.com/2010/01/episerver-code-walkthrough-1-404-handler/" rel="bookmark" title="January 29, 2010">EPiServer code walkthrough #1 &#8211; 404 handler</a></li>
</ul>
<p><!-- Similar Posts took 24.587 ms --></p>
<img src="http://feeds.feedburner.com/~r/frederikvig/~4/XP5GkJbGTOI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2012/02/open-source-mobilepack-version-1-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.frederikvig.com/2012/02/open-source-mobilepack-version-1-0/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=open-source-mobilepack-version-1-0</feedburner:origLink></item>
		<item>
		<title>Geta.oEmbed version 1.2 is out</title>
		<link>http://feedproxy.google.com/~r/frederikvig/~3/Rk5IXQvfniw/</link>
		<comments>http://www.frederikvig.com/2011/11/geta-oembed-version-1-2-is-out/#comments</comments>
		<pubDate>Sat, 19 Nov 2011 18:50:59 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[geta]]></category>
		<category><![CDATA[oembed]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1711</guid>
		<description><![CDATA[Due to a changes in the oEmbed API I&#8217;m using for this module (it got bought by Embedly), I&#8217;ve updated the code to use the new API instead. The biggest change on your part is that you need to register on Embedly to obtain a key for the API. Registration To get the key register ...]]></description>
			<content:encoded><![CDATA[<p>Due to a changes in the oEmbed API I&#8217;m using for this module (it got bought by <a href="http://embed.ly">Embedly</a>), I&#8217;ve updated the code to use the new API instead. The biggest change on your part is that you need to register on <a href="http://embed.ly">Embedly</a> to obtain a key for the API.</p>
<h3>Registration</h3>
<p>To get the key register on this page: <a href="http://embed.ly/pricing">Embedly Pricing Plan</a>, if you scroll to the bottom you&#8217;ll see the free version which should be plenty for most uses (there is among other things a restriction on the number of requests).</p>
<p>After the registration you should receive the key in your email inbox. Add this key to your sites appSettings configuration.</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;add</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;EmbedKey&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;your-key-goes-here&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre>
</div>
</div>
<p>The great thing about Embedly is the support for <strong>220 different providers</strong>, here&#8217;s the list: <a href="http://embed.ly/providers">Providers</a>.</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/oembed-providers.png" alt="oEmbed providers" />
</p>
<h3>Upgrade</h3>
<p>You can get the latest version (Geta.oEmbed 1.2) from <a href="http://nuget.episerver.com">nuget.episerver.com</a>, or download the source code from <a href="https://bitbucket.org/GetaAS/opensource">Geta&#8217;s Open Source repository</a>.</p>
<p> <strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2010/09/introducing-oembed-for-episerver/" rel="bookmark" title="September 25, 2010">Introducing oEmbed for EPiServer</a></li>
<li><a href="http://www.frederikvig.com/2012/05/faster-episerver-sites-image-optimization/" rel="bookmark" title="May 6, 2012">Faster EPiServer sites &#8211; image optimization</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-1-setting-up-the-development-environment-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 4, 2009">Part 1: Setting up the development environment &#8211; Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2009/10/creating-a-mobile-version-of-a-web-site/" rel="bookmark" title="October 4, 2009">Creating a mobile version of a web site</a></li>
<li><a href="http://www.frederikvig.com/2011/09/tags-version-0-2-released-for-episerver-cms/" rel="bookmark" title="September 5, 2011">Tags version 0.2 released for EPiServer CMS</a></li>
</ul>
<p><!-- Similar Posts took 25.738 ms --></p>
<img src="http://feeds.feedburner.com/~r/frederikvig/~4/Rk5IXQvfniw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2011/11/geta-oembed-version-1-2-is-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.frederikvig.com/2011/11/geta-oembed-version-1-2-is-out/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=geta-oembed-version-1-2-is-out</feedburner:origLink></item>
		<item>
		<title>Faster EPiServer sites – client side performance</title>
		<link>http://feedproxy.google.com/~r/frederikvig/~3/5L9UChXJuxE/</link>
		<comments>http://www.frederikvig.com/2011/10/faster-episerver-sites-client-side-performance/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 08:59:04 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Scaling]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1681</guid>
		<description><![CDATA[First part of a new series where I&#8217;m going to focus on performance and scaling. I&#8217;m going to go through all the best practices we as EPiServer developers should know about, not only to create EPiServer sites that are fast, but ultra-fast. I&#8217;m going to use the Overlook hotel sample site. The goal is of ...]]></description>
			<content:encoded><![CDATA[<p>First part of a new series where I&#8217;m going to focus on performance and scaling. I&#8217;m going to go through all the best practices we as EPiServer developers should know about, not only to create EPiServer sites that are fast, but ultra-fast.</p>
<p>I&#8217;m going to use the <a href="http://world.episerver.com/Download/Items/EPiServer-CMS/EPiServer-CMS-6-R2/EPiServer-Overlook-R2-Demo-Site/">Overlook hotel sample site</a>. The goal is of course to make it ultra-fast!</p>
<p>To follow along you should have the overlook site installed and setup. Let&#8217;s get started!</p>
<h2>Client side performance</h2>
<p>I&#8217;m using Firefox as my main developer browser, I&#8217;ll also be using three great addons for Firefox: <a href="http://getfirebug.com/">Firebug</a>, <a href="http://developer.yahoo.com/yslow/">YSlow</a>, and <a href="http://code.google.com/speed/page-speed/">Page Speed</a>.</p>
<p>If we run YSlow on the front page of overlook hotel we&#8217;ll get a score of 66/100 (grade D) with a few suggestions for improvements.</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/performance/yslow-before.png" alt="YSlow - EPiServer Overlook Hotel demo site before" />
</p>
<p>With Page Speed we get a score of 62/100.</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/performance/page-speed-before.png" alt="Page Speed - EPiServer Overlook Hotel demo site before" />
</p>
<p>I&#8217;m going to focus on IIS 7 and above, most of the stuff is also possible with IIS 6, but I&#8217;m not going to go through IIS 6.</p>
<h3>Compress components with gzip</h3>
<p>Read more about the benefits of gzipping your content here: <a href="http://developer.yahoo.com/performance/rules.html#gzip">Gzip Components</a>. </p>
<p>In IIS 7 this is very easy. First make sure you have both static and dynamic compression installed.</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/performance/gzip-compression-iis-features.png" alt="Install Static and Dynamic compression features in IIS 7" />
</p>
<p>Next step is enabling both static and dynamic compression in web.config. Go to the &lt;system.webServer&gt; section and add 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;urlCompression</span> <span style="color: #000066;">doDynamicCompression</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">doStaticCompression</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">dynamicCompressionBeforeCache</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre>
</div>
</div>
<p>Re-run both YSlow and Page Speed. Your score should now be 72 and 78 with an A in gzip.</p>
<p>You can find more information on <a href="http://www.iis.net/ConfigReference/system.webServer/urlCompression">urlCompression on IIS.NET</a>. By default IIS 7 will actually enable static and dynamic compression for you.</p>
<p>You might have spotted the httpCompression section under &lt;system.webServer&gt;.</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;httpCompression<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;staticTypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;text/*&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;message/*&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;application/javascript&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;application/x-javascript&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;*/*&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/staticTypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dynamicTypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;text/*&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;message/*&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;application/javascript&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;application/x-javascript&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;*/*&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dynamicTypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scheme</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;gzip&quot;</span> <span style="color: #000066;">dll</span>=<span style="color: #ff0000;">&quot;%Windir%\system32\inetsrv\gzip.dll&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/httpCompression<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>You don&#8217;t actually need this section to enable gzip (IIS will just use it&#8217;s default settings), but it&#8217;s nice to know about it when you need to tweak your default gzip settings a bit. Basically urlCompression specifies what to compress and httpCompression specifies how. More information on httpCompression: <a href="http://www.iis.net/ConfigReference/system.webServer/httpCompression">HTTP Compression &lt;httpCompression&gt;</a>.</p>
<p>If we check the applicationHost.config file for IIS 7 you can see the default settings (location: %windir%\system32\inetsrv\config\applicationHost.config):</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>httpCompression directory<span style="color: #008000;">=</span><span style="color: #666666;">&quot;%SystemDrive%<span style="color: #008080; font-weight: bold;">\i</span>netpub<span style="color: #008080; font-weight: bold;">\t</span>emp<span style="color: #008080; font-weight: bold;">\I</span>IS Temporary Compressed Files&quot;</span><span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;</span>scheme name<span style="color: #008000;">=</span><span style="color: #666666;">&quot;gzip&quot;</span> dll<span style="color: #008000;">=</span><span style="color: #666666;">&quot;%Windir%<span style="color: #008080; font-weight: bold;">\s</span>ystem32<span style="color: #008080; font-weight: bold;">\i</span>netsrv<span style="color: #008080; font-weight: bold;">\g</span>zip.dll&quot;</span> <span style="color: #008000;">/&gt;</span>
	<span style="color: #008000;">&lt;</span>staticTypes<span style="color: #008000;">&gt;</span>
		<span style="color: #008000;">&lt;</span>add mimeType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;text/*&quot;</span> enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> <span style="color: #008000;">/&gt;</span>
		<span style="color: #008000;">&lt;</span>add mimeType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;message/*&quot;</span> enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> <span style="color: #008000;">/&gt;</span>
		<span style="color: #008000;">&lt;</span>add mimeType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;application/x-javascript&quot;</span> enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> <span style="color: #008000;">/&gt;</span>
		<span style="color: #008000;">&lt;</span>add mimeType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;application/atom+xml&quot;</span> enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> <span style="color: #008000;">/&gt;</span>
		<span style="color: #008000;">&lt;</span>add mimeType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;application/xaml+xml&quot;</span> enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> <span style="color: #008000;">/&gt;</span>
		<span style="color: #008000;">&lt;</span>add mimeType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;*/*&quot;</span> enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> <span style="color: #008000;">/&gt;</span>
	<span style="color: #008000;">&lt;/</span>staticTypes<span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;</span>dynamicTypes<span style="color: #008000;">&gt;</span>
		<span style="color: #008000;">&lt;</span>add mimeType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;text/*&quot;</span> enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> <span style="color: #008000;">/&gt;</span>
		<span style="color: #008000;">&lt;</span>add mimeType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;message/*&quot;</span> enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> <span style="color: #008000;">/&gt;</span>
		<span style="color: #008000;">&lt;</span>add mimeType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;application/x-javascript&quot;</span> enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> <span style="color: #008000;">/&gt;</span>
		<span style="color: #008000;">&lt;</span>add mimeType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;*/*&quot;</span> enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> <span style="color: #008000;">/&gt;</span>
	<span style="color: #008000;">&lt;/</span>dynamicTypes<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>httpCompression<span style="color: #008000;">&gt;</span></pre>
</div>
</div>
<p>By default httpCompression is set to only gzip files over 2700 bytes, we can fix this by adding the following code:</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;httpCompression</span> <span style="color: #000066;">directory</span>=<span style="color: #ff0000;">&quot;%SystemDrive%\websites\_compressed&quot;</span> <span style="color: #000066;">minFileSizeForComp</span>=<span style="color: #ff0000;">&quot;1024&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scheme</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;gzip&quot;</span> <span style="color: #000066;">dll</span>=<span style="color: #ff0000;">&quot;%Windir%\system32\inetsrv\gzip.dll&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;staticTypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;text/*&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;message/*&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;application/javascript&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;application/json&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">mimeType</span>=<span style="color: #ff0000;">&quot;*/*&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/staticTypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/httpCompression<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<h3>Add Expires headers</h3>
<p>Adding Expires headers to static and dynamic files like CSS, JavaScript and images tells the client to cache the files locally, lessening the burden on the server (less requests). Making your sites resources/components cache-able. More information: <a href="developer.yahoo.com/performance/rules.html#expires">Add an Expires or a Cache-Control Header</a>.</p>
<p>Back in our sites web.config file under the &lt;system.webServer&gt; section, we have the &lt;staticContent&gt; section:</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;staticContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;clientCache</span> <span style="color: #000066;">cacheControlMode</span>=<span style="color: #ff0000;">&quot;UseMaxAge&quot;</span> <span style="color: #000066;">cacheControlMaxAge</span>=<span style="color: #ff0000;">&quot;1.00:00:00&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/clientCache<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/staticContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>The interesting part here is of course the <a href="http://www.iis.net/ConfigReference/system.webServer/staticContent/clientCache">clientCache element</a>. </p>
<p>UseMaxAge will add CacheControlMaxAge to the HTTP Headers sent to the client, we can then tell the client to cache the static files for 1 year:</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;staticContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;clientCache</span> <span style="color: #000066;">cacheControlMode</span>=<span style="color: #ff0000;">&quot;UseMaxAge&quot;</span> <span style="color: #000066;">cacheControlMaxAge</span>=<span style="color: #ff0000;">&quot;365.00:00:00&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/staticContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>With UseExpires you specify a date instead:</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;staticContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;clientCache</span> <span style="color: #000066;">cacheControlMode</span>=<span style="color: #ff0000;">&quot;UseExpires&quot;</span> <span style="color: #000066;">httpExpires</span>=<span style="color: #ff0000;">&quot;Tue, 19 Jan 2038 03:14:07 GMT&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/staticContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>You can only use one of these (if you&#8217;re not using the location element) at a time. I usually use MaxAge, it&#8217;s simpler and you don&#8217;t have to remember to update your settings when the date passes. </p>
<p>The important thing to remember is that if you make any changes to the static files you&#8217;ll need to use another name. You can add a querystring, change the name, or in some other way update the path to reflect that the file has changed.</p>
<p>Let&#8217;s update it to say that the client should cache the files for 1 year:</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;staticContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;clientCache</span> <span style="color: #000066;">cacheControlMode</span>=<span style="color: #ff0000;">&quot;UseMaxAge&quot;</span> <span style="color: #000066;">cacheControlMaxAge</span>=<span style="color: #ff0000;">&quot;365.00:00:00&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/staticContent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>This helped bring the list of components down from 86 to 15. But we&#8217;re not quite finished yet.</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/performance/expires-headers-yslow1.png" alt="Down from 86 to 15 files in YSlow Add Expires headers" />
</p>
<p>EPiServer uses the location element to specify access rights and to use EPiServer&#8217;s StaticFileHandler for files located in Global Files, Page Files, Documents and other places that use Virtual Path Providers.</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;location</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;PageFiles&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.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;handlers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;webresources&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;WebResource.axd&quot;</span> <span style="color: #000066;">verb</span>=<span style="color: #ff0000;">&quot;GET&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;System.Web.Handlers.AssemblyResourceLoader&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;wildcard&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000066;">verb</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;EPiServer.Web.StaticFileHandler, EPiServer&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/handlers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;staticFile</span> <span style="color: #000066;">expirationTime</span>=<span style="color: #ff0000;">&quot;365.00:00:00&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/location<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;location</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;Documents&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.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;handlers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;webresources&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;WebResource.axd&quot;</span> <span style="color: #000066;">verb</span>=<span style="color: #ff0000;">&quot;GET&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;System.Web.Handlers.AssemblyResourceLoader&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;wildcard&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000066;">verb</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;EPiServer.Web.StaticFileHandler, EPiServer&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/handlers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;staticFile</span> <span style="color: #000066;">expirationTime</span>=<span style="color: #ff0000;">&quot;365.00:00:00&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/location<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;location</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;Global&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.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;handlers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;webresources&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;WebResource.axd&quot;</span> <span style="color: #000066;">verb</span>=<span style="color: #ff0000;">&quot;GET&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;System.Web.Handlers.AssemblyResourceLoader&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;wildcard&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000066;">verb</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;EPiServer.Web.StaticFileHandler, EPiServer&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/handlers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;staticFile</span> <span style="color: #000066;">expirationTime</span>=<span style="color: #ff0000;">&quot;365.00:00:00&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/location<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>More information in EPiServer&#8217;s SDK: <a href="http://sdk.episerver.com/library/cms6/Developers%20Guide/Advanced%20Features/Caching/StaticFileCaching.htm">Caching of static files</a>. This technique uses the Expires header instead of MaxAge, but with the same effect.</p>
<p>You might have noticed the &lt;caching&gt; section:</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;caching<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;profiles<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">extension</span>=<span style="color: #ff0000;">&quot;.gif&quot;</span> <span style="color: #000066;">policy</span>=<span style="color: #ff0000;">&quot;DontCache&quot;</span> <span style="color: #000066;">kernelCachePolicy</span>=<span style="color: #ff0000;">&quot;CacheUntilChange&quot;</span> <span style="color: #000066;">duration</span>=<span style="color: #ff0000;">&quot;0.00:01:00&quot;</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;Any&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">extension</span>=<span style="color: #ff0000;">&quot;.png&quot;</span> <span style="color: #000066;">policy</span>=<span style="color: #ff0000;">&quot;DontCache&quot;</span> <span style="color: #000066;">kernelCachePolicy</span>=<span style="color: #ff0000;">&quot;CacheUntilChange&quot;</span> <span style="color: #000066;">duration</span>=<span style="color: #ff0000;">&quot;0.00:01:00&quot;</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;Any&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">extension</span>=<span style="color: #ff0000;">&quot;.js&quot;</span> <span style="color: #000066;">policy</span>=<span style="color: #ff0000;">&quot;DontCache&quot;</span> <span style="color: #000066;">kernelCachePolicy</span>=<span style="color: #ff0000;">&quot;CacheUntilChange&quot;</span> <span style="color: #000066;">duration</span>=<span style="color: #ff0000;">&quot;0.00:01:00&quot;</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;Any&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">extension</span>=<span style="color: #ff0000;">&quot;.css&quot;</span> <span style="color: #000066;">policy</span>=<span style="color: #ff0000;">&quot;DontCache&quot;</span> <span style="color: #000066;">kernelCachePolicy</span>=<span style="color: #ff0000;">&quot;CacheUntilChange&quot;</span> <span style="color: #000066;">duration</span>=<span style="color: #ff0000;">&quot;0.00:01:00&quot;</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;Any&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">extension</span>=<span style="color: #ff0000;">&quot;.jpg&quot;</span> <span style="color: #000066;">policy</span>=<span style="color: #ff0000;">&quot;DontCache&quot;</span> <span style="color: #000066;">kernelCachePolicy</span>=<span style="color: #ff0000;">&quot;CacheUntilChange&quot;</span> <span style="color: #000066;">duration</span>=<span style="color: #ff0000;">&quot;0.00:01:00&quot;</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;Any&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">extension</span>=<span style="color: #ff0000;">&quot;.jpeg&quot;</span> <span style="color: #000066;">policy</span>=<span style="color: #ff0000;">&quot;DontCache&quot;</span> <span style="color: #000066;">kernelCachePolicy</span>=<span style="color: #ff0000;">&quot;CacheUntilChange&quot;</span> <span style="color: #000066;">duration</span>=<span style="color: #ff0000;">&quot;0.00:01:00&quot;</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;Any&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/profiles<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/caching<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>The caching setting is used to configure output caching for IIS. You have both output caching for IIS and for ASP.NET. More information: <a href="http://www.iis.net/ConfigReference/system.webServer/caching">Caching &lt;caching&gt;</a>. By default IIS output caching is turned on. </p>
<p>What EPiServer has done is told IIS to not cache static files like images, CSS and JavaScript and let ASP.NET handle it instead. You can read more about IIS output caching here: <a href="http://learn.iis.net/page.aspx/710/configure-iis-7-output-caching/">Configure IIS 7 Output Caching</a>.</p>
<p>Let&#8217;s remove the whole &lt;caching&gt; section and use the default settings instead. </p>
<p>Now we have a score of 78 points in YSlow and 95 in Page Speed. Here you can see how much of the total size is now cached:</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/performance/yslow-cache.png" alt="YSlow showing the pages local cache" />
</p>
<p>On the left we can see the total size and number of requests the first time, on the right is the size and number of requests after that. We&#8217;re now down to 3 requests and 16KB. Quite an improvement don&#8217;t you think?</p>
<h3>Minify JavaScript and CSS</h3>
<p>When we&#8217;re developing we usually work with multiple JavaScript and CSS files to make it easier to structure and maintain them. However in production we should take care to automatically compress and bundle the files.</p>
<p>It&#8217;s important to note the difference between the rule <a href="http://developer.yahoo.com/performance/rules.html#gzip">Gzip Components</a> and <a href="http://developer.yahoo.com/performance/rules.html#minify">Minify JavaScript and CSS</a>, which will remove comments, unneeded whitespaces and replace variable/function names with shorter versions.</p>
<p>There are a few tools we can use for this:</p>
<ul>
<li><a href="http://nuget.org/List/Packages/SquishIt">SquishIt</a> &#8211; I&#8217;ve written about it before: <a href="http://www.frederikvig.com/2010/06/css-and-javascript-compression-and-bundling/">CSS and JavaScript compression and bundling</a></li>
<li><a href="http://nuget.org/List/Packages/Cassette.Web">Cassette</a></li>
<li><a href="http://nuget.org/List/Packages/Microsoft.Web.Optimization">ASP.NET 4.5 Optimization</a></li>
</ul>
<p>We&#8217;re going to use ASP.NET 4.5 Optimization preview. You can easily install it through NuGet. </p>
<p>Note: you&#8217;ll need to run .NET 4, so we&#8217;ll need to upgrade our solution to use .NET 4 instead of .NET 3.5. This is quite easy thanks to <a href="http://twitter.com/davidknipeta">David Knipe</a>. Change the projects target framework in Visual Studio and install the EPiServerCMS6ToNetFour package from <a href="http://nuget.episerver.com">nuget.episerver.com</a>.</p>
<p>After that you&#8217;ll be able to install ASP.NET 4.5 Optimization successfully. </p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/performance/nuget-asp-net-optimization.png" alt="ASP.NET 4.5 Optimization installation with NuGet in Visual Studio 2010" />
</p>
<p>To enable it we just call the EnableDefaultBundles() method inside Application_Start in Global.asax:</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> Global <span style="color: #008000;">:</span> EPiServer<span style="color: #008000;">.</span><span style="color: #0000FF;">Global</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> Application_Start<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		BundleTable<span style="color: #008000;">.</span><span style="color: #0000FF;">Bundles</span><span style="color: #008000;">.</span><span style="color: #0000FF;">EnableDefaultBundles</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<p>Next step is updating the way external JavaScript and CSS files are included. By default, everything you refer to in a folder gets bundled together (only for the same type, so JavaScript and CSS files don&#8217;t get bundled together even if they&#8217;re in the same folder).</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;">link</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/Templates/DemoSite/Styles/Main/css&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/Templates/DemoSite/Scripts/Main/js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre>
</div>
</div>
<p>We add the path to the folder followed by either /css or /js.</p>
<p>I had to manually update the code-behind files of site.master and the composer functions and change:</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;">Page<span style="color: #008000;">.</span><span style="color: #0000FF;">RegisterCSSFile</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ComposerFunctions.Teaser.Styles.Teaser.css&quot;</span>, UriSupport<span style="color: #008000;">.</span><span style="color: #0000FF;">ResolveUrlBySettings</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;/Templates/DemoSite/ComposerFunctions/Teaser/Styles/Teaser.css&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<p>To:</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;">Page<span style="color: #008000;">.</span><span style="color: #0000FF;">RegisterCSSFile</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ComposerFunctions.Teaser.Styles.Teaser.css&quot;</span>, UriSupport<span style="color: #008000;">.</span><span style="color: #0000FF;">ResolveUrlBySettings</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;/Templates/DemoSite/ComposerFunctions/Teaser/Styles/css&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</div>
</div>
<p>What I did was bundle the different JavaScript and CSS files into folders like components/modules and updated their references to use these folders instead.</p>
<p>There were a few inline scripts that I didn&#8217;t compress, but overall this helped a lot. I have now 97/100 points in Page Speed and 79/100 in YSlow.</p>
<h3>Make fewer HTTP requests</h3>
<p>Modern browsers can send up-to 6 requests at a time to the same domain. Older browsers up-to 2. Combining resource files like JavaScript, CSS and images into as few files as possible not only decreases the sites total size, but also make it load much faster for the client.</p>
<p>For JavaScript and CSS files we can use the technique we learned in the previous step (Minify JavaScript and CSS). For images we can use CSS sprites or embed the images.</p>
<p>What we&#8217;re going to do is embed the CSS background images into the stylsheets. I&#8217;ve borrowed the code from Mads Kristensen&#8217;s presentation on <a href="http://channel9.msdn.com/Events/BUILD/BUILD2011/SAC-837T">Build &#8211; Optimize your website using ASP.NET and IIS8</a>.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text.RegularExpressions</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.Hosting</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Web.Optimization</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> EPiServer
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> CssWithImagesMinify <span style="color: #008000;">:</span> CssMinify
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> Regex url <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Regex<span style="color: #008000;">&#40;</span><span style="color: #666666;">@&quot;url\((([^\)]*)\?embed)\)&quot;</span>, RegexOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">Singleline</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">string</span> format <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;url(data:image/{0};base64,{1})&quot;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Process<span style="color: #008000;">&#40;</span>BundleResponse bundle<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Response</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Cache</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SetLastModifiedFromFileDependencies</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Process</span><span style="color: #008000;">&#40;</span>bundle<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> reference <span style="color: #008000;">=</span> HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Request</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Path</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Replace</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;/css&quot;</span>, <span style="color: #666666;">&quot;/&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// When publishing the bundler can be called from &quot;/&quot; causing image reference to be invalid.</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>reference <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;/&quot;</span><span style="color: #008000;">&#41;</span>
                reference <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;/Content/&quot;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>Match match <span style="color: #0600FF; font-weight: bold;">in</span> url<span style="color: #008000;">.</span><span style="color: #0000FF;">Matches</span><span style="color: #008000;">&#40;</span>bundle<span style="color: #008000;">.</span><span style="color: #0000FF;">Content</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                var file <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> FileInfo<span style="color: #008000;">&#40;</span>HostingEnvironment<span style="color: #008000;">.</span><span style="color: #0000FF;">MapPath</span><span style="color: #008000;">&#40;</span>reference <span style="color: #008000;">+</span> match<span style="color: #008000;">.</span><span style="color: #0000FF;">Groups</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>file<span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #6666cc; font-weight: bold;">string</span> dataUri <span style="color: #008000;">=</span> GetDataUri<span style="color: #008000;">&#40;</span>file<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    bundle<span style="color: #008000;">.</span><span style="color: #0000FF;">Content</span> <span style="color: #008000;">=</span> bundle<span style="color: #008000;">.</span><span style="color: #0000FF;">Content</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Replace</span><span style="color: #008000;">&#40;</span>match<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span>, dataUri<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Response</span><span style="color: #008000;">.</span><span style="color: #0000FF;">AddFileDependency</span><span style="color: #008000;">&#40;</span>file<span style="color: #008000;">.</span><span style="color: #0000FF;">FullName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetDataUri<span style="color: #008000;">&#40;</span>FileInfo file<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> buffer <span style="color: #008000;">=</span> File<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadAllBytes</span><span style="color: #008000;">&#40;</span>file<span style="color: #008000;">.</span><span style="color: #0000FF;">FullName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> ext <span style="color: #008000;">=</span> file<span style="color: #008000;">.</span><span style="color: #0000FF;">Extension</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Substring</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span>format, ext, Convert<span style="color: #008000;">.</span><span style="color: #0000FF;">ToBase64String</span><span style="color: #008000;">&#40;</span>buffer<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<p>For all the images we want to embed we just add ?embed behind their name:</p>
<div class="wp_syntax">
<div class="code">
<pre class="css" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'../Images/abuse.png?embed'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #993333;">scroll</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span></pre>
</div>
</div>
<p>We also need to update Global.asax and tell BundleTable to use our CSS Minifier instead.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> Application_Start<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	var css <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DynamicFolderBundle<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;css&quot;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>CssWithImagesMinify<span style="color: #008000;">&#41;</span>, <span style="color: #666666;">&quot;*.css&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	var js <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DynamicFolderBundle<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;js&quot;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>JsMinify<span style="color: #008000;">&#41;</span>, <span style="color: #666666;">&quot;*.js&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	BundleTable<span style="color: #008000;">.</span><span style="color: #0000FF;">Bundles</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>css<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	BundleTable<span style="color: #008000;">.</span><span style="color: #0000FF;">Bundles</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>js<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<p>The CSS files now have their background images embedded automatically!</p>
<div class="wp_syntax">
<div class="code">
<pre class="css" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA5IAAAAFCAYAAAA3+tN0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAGFJREFUeNrs1zEKg1AQRdE/VgYN4uZcZDYXxEDSfd8W0gmeA5fpp3vVWpvSmB5pTs+0pLX3/moAAADcTlVtOe+0pyN90jf9Bu8BAADgH4YkAAAAhiQAAACGJAAAABdxCjAAa0EKFYXT/VsAAAAASUVORK5CYII=&quot;</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat-y</span> <span style="color: #993333;">scroll</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span></pre>
</div>
</div>
<p>There&#8217;s also a nice extension for Visual Studio that let&#8217;s right-click a folder inside Visual Studio and optimize all the images inside that folder: <a href="http://visualstudiogallery.msdn.microsoft.com/a56eddd3-d79b-48ac-8c8f-2db06ade77c3">Image Optimizer</a>.</p>
<p>I now have 99/100 in Page Speed and 95/100 in YSlow.</p>
<h3>Further improvements</h3>
<ul>
<li>Use a CDN &#8211; See <a href="http://developer.yahoo.com/performance/rules.html#cdn">Use a Content Delivery Network</a> and <a href="http://world.episerver.com/Blogs/Andre-Brynildsen/Dates/2011/9/Virtual-Path-Provider-for-Amazon-S3/">Virtual Path Provider for Amazon S3</a></li>
<li>Remove whitespaces and comments from HTML markup</li>
<li>Optimize CSS selectors and placement of stylesheets</li>
<li>Optimize JavaScript code, especially jQuery, remove inline code and update the placement of the JavaScript code</li>
<li><a href="http://developer.yahoo.com/performance/rules.html#dns_lookups">Reduce DNS Lookups</a> and consider using a service like <a href="http://aws.amazon.com/route53/">Amazon&#8217;s Route 53</a> for faster DNS lookups</li>
</ul>
<h3>Resources</h3>
<ul>
<li><a href="http://developer.yahoo.com/performance/rules.html">Best Practices for Speeding Up Your Web Site</a></li>
<li><a href="http://jsperf.com/">jsPerf — JavaScript performance playground</a></li>
<li><a href="http://www.webpagetest.org/">WebPageTest &#8211; Test a website&#8217;s performance</a></li>
<li><a href="http://yostudios.github.com/Spritemapper/">Spritemapper &#8211; CSS Spritemap Generator</a></li>
<li><a href="http://pagespeed.googlelabs.com/pagespeed/">Page Speed Online</a></li>
<li><a href="http://nuget.org/List/Packages/AspNetSprites-Core">ASP.NET CSS Sprites</a></li>
</ul>
<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2010/06/css-and-javascript-compression-and-bundling/" rel="bookmark" title="June 20, 2010">CSS and JavaScript compression and bundling</a></li>
<li><a href="http://www.frederikvig.com/2009/08/adding-css-and-javascript-files-dynamically-to-your-asp-net-page/" rel="bookmark" title="August 15, 2009">Adding CSS and JavaScript files dynamically to your ASP.NET page</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-8-preparing-for-launch-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 24, 2009">Part 8: Preparing for launch – Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2009/05/transparent-pngs/" rel="bookmark" title="May 5, 2009">Transparent PNGs</a></li>
<li><a href="http://www.frederikvig.com/2011/10/installing-episerver-live-monitor-on-iis-7-running-net-4/" rel="bookmark" title="October 7, 2011">Installing EPiServer Live Monitor on IIS 7 running .NET 4</a></li>
</ul>
<p><!-- Similar Posts took 41.132 ms --></p>
<img src="http://feeds.feedburner.com/~r/frederikvig/~4/5L9UChXJuxE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2011/10/faster-episerver-sites-client-side-performance/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://www.frederikvig.com/2011/10/faster-episerver-sites-client-side-performance/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=faster-episerver-sites-client-side-performance</feedburner:origLink></item>
		<item>
		<title>Installing EPiServer Live Monitor on IIS 7 running .NET 4</title>
		<link>http://feedproxy.google.com/~r/frederikvig/~3/CGQ1jVts794/</link>
		<comments>http://www.frederikvig.com/2011/10/installing-episerver-live-monitor-on-iis-7-running-net-4/#comments</comments>
		<pubDate>Fri, 07 Oct 2011 14:08:12 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[EPiServer]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1673</guid>
		<description><![CDATA[A client asked me to install Live Monitor for EPiServer CMS on their site today. Simple enough task, I started by reading the tech-note for the installation: Installation Instructions &#8211; Live Monitor. First problem Where is the installation file!? After a little digging around I found out that it was in the zip file for ...]]></description>
			<content:encoded><![CDATA[<p>A client asked me to install Live Monitor for EPiServer CMS on their site today. Simple enough task, I started by reading the tech-note for the installation: <a href="http://world.episerver.com/Documentation/Items/Installation-Instructions/EPiServer-CMS/Version-6/EPiServer-CMS-6-R2/Installation-Instructions---Live-Monitor/">Installation Instructions &#8211; Live Monitor</a>. </p>
<h3>First problem</h3>
<p>Where is the installation file!? After a little digging around I found out that it was in the <a href="http://world.episerver.com/Download/Items/EPiServer-CMS/EPiServer-CMS-6-R2/">zip file for EPiServer CMS</a> (Live Monitor.msi). After the installation Live Monitor was now available under the Modules node in EPiServer Deployment Center.</p>
<h3>Second problem</h3>
<p>Since we&#8217;re using Web.config transformation for updating our configurations files (web.config, episerver.config etc) when we deploy to different environments (test, staging, production), we&#8217;ve removed the namespace for episerver.config (xmlns=&#8221;http://EPiServer.Configuration.EPiServerSection&#8221;). If you try to run the installation without this namespace, you&#8217;ll get the following error:</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/live-monitor/second-problem.png" alt="EPiServer Live Monitor - Error - Cannot validate argument on parameter 'SqlServerName'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again." />
</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;episerver</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://EPiServer.Configuration.EPiServerSection&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span></pre>
</div>
</div>
<p>Adding the namespace and rerunning the installation made the error disappear.</p>
<h3>Third problem</h3>
<p>Everything seemed to be running smoothly until I logged in and visited the Live Monitor overview. I get an error message:</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/live-monitor/third-problem.png" alt="EPiServer Live Monitor Failed to load root node!" />
</p>
<p>I suspected something was wrong with my web.config file after the installation. Since the site is running .NET 4, everytime I update or install EPiServer products/modules I need to update the new stuff that gets added. I&#8217;m using a source control system (of course you&#8217;re too), so it was quite easy for me to spot the new stuff that the Live Monitor installation added.</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;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;svc-Integrated&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;*.svc&quot;</span> <span style="color: #000066;">verb</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&quot;</span> <span style="color: #000066;">resourceType</span>=<span style="color: #ff0000;">&quot;Unspecified&quot;</span> <span style="color: #000066;">preCondition</span>=<span style="color: #ff0000;">&quot;integratedMode&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre>
</div>
</div>
<p>Should be:</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;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;svc-Integrated&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;*.svc&quot;</span> <span style="color: #000066;">verb</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;System.ServiceModel.Activation.HttpHandler, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&quot;</span> <span style="color: #000066;">resourceType</span>=<span style="color: #ff0000;">&quot;Unspecified&quot;</span> <span style="color: #000066;">preCondition</span>=<span style="color: #ff0000;">&quot;integratedMode&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre>
</div>
</div>
<p>Cool, now I get a nice overview over the site. But there are no visitors!</p>
<h3>Fourth and last problem</h3>
<p>First I suspected that <a href="http://world.episerver.com/Documentation/Items/Installation-Instructions/EPiServer-CMS/Version-6/EPiServer-CMS-6-R2/Installation-Instructions---Live-Monitor/#usage3">the tracking code wasn&#8217;t added</a>, but a quick view source showed that everything was fine there. I then opened up Firebug and saw that I got a 404 error for TrackerHandler.ashx. Having a peek at web.config again I spotted that TrackerHandler.ascx was registered in the handlers section followed by &lt;clear /&gt;.</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;handlers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;EPiTraceTracker&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;TrackerHandler.ashx&quot;</span> <span style="color: #000066;">verb</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;EPiServer.Trace.CMS.Handlers.TrackerHandler&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;clear</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre>
</div>
</div>
<p>Moving TrackerHandler.ashx after the &lt;clear /&gt; removed the 404 error and we have visitors showing up on Live Monitors overview!</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/live-monitor/fourth-problem.png" alt="EPiServer Live Monitor is running and tracking users" />
</p>
<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2012/05/manually-upgrading-the-database-from-episerver-commerce-r2-sp1-to-episerver-commerce-r2-sp2/" rel="bookmark" title="May 9, 2012">Manually upgrading the database from EPiServer Commerce R2 SP1 to EPiServer Commerce R2 SP2</a></li>
<li><a href="http://www.frederikvig.com/2012/05/faster-episerver-sites-image-optimization/" rel="bookmark" title="May 6, 2012">Faster EPiServer sites &#8211; image optimization</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-8-preparing-for-launch-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 24, 2009">Part 8: Preparing for launch – Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2010/01/episerver-code-walkthrough-1-404-handler/" rel="bookmark" title="January 29, 2010">EPiServer code walkthrough #1 &#8211; 404 handler</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-1-setting-up-the-development-environment-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 4, 2009">Part 1: Setting up the development environment &#8211; Create an EPiServer site from scratch</a></li>
</ul>
<p><!-- Similar Posts took 55.502 ms --></p>
<img src="http://feeds.feedburner.com/~r/frederikvig/~4/CGQ1jVts794" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2011/10/installing-episerver-live-monitor-on-iis-7-running-net-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.frederikvig.com/2011/10/installing-episerver-live-monitor-on-iis-7-running-net-4/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=installing-episerver-live-monitor-on-iis-7-running-net-4</feedburner:origLink></item>
		<item>
		<title>Tags version 0.2 released for EPiServer CMS</title>
		<link>http://feedproxy.google.com/~r/frederikvig/~3/fB00TJfTukE/</link>
		<comments>http://www.frederikvig.com/2011/09/tags-version-0-2-released-for-episerver-cms/#comments</comments>
		<pubDate>Mon, 05 Sep 2011 18:04:56 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[Geta.Tags]]></category>
		<category><![CDATA[Tags]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1643</guid>
		<description><![CDATA[I&#8217;ve done a few updates to the Tags module for EPiServer CMS. The major change is that it&#8217;s now using the page&#8217;s PageGuid instead of PageLink (PageReference). This guaranties that the reference to the page will be correct, even when used with mirroring. The other updates I&#8217;ve done is added a scheduled job that cleans ...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve done a few updates to the <a href="http://www.frederikvig.com/2011/07/tags-for-episerver-cms/">Tags module for EPiServer CMS</a>. The major change is that it&#8217;s now using the page&#8217;s PageGuid instead of PageLink (PageReference). This guaranties that the reference to the page will be correct, even when used with mirroring. </p>
<p>The other updates I&#8217;ve done is added a scheduled job that cleans up and check&#8217;s that the tagged pages still exist and that they still have their tag. You&#8217;ll need to manually set this up in admin mode. Depending on the size of the site I&#8217;ll usually set this to 30 minutes. The job goes through all pages that have a tag and validates them.</p>
<p>
<img src="http://www.frederikvig.com/wp-content/uploads/tags-scheduled-job.png" alt="Tags maintenance job in EPiServer admin mode" />
</p>
<p>I&#8217;ve also implemented the TagEngine. This is a very first version so expect a few updates here soon. Here&#8217;s ITagEngine.cs</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">EPiServer.Core</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Geta.Tags.Models</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> Geta<span style="color: #008000;">.</span><span style="color: #0000FF;">Tags</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Interfaces</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">interface</span> ITagEngine
    <span style="color: #008000;">&#123;</span>
        PageDataCollection GetPagesByTag<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> tagName<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        PageDataCollection GetPagesByTag<span style="color: #008000;">&#40;</span>Tag tag<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        PageDataCollection GetPagesByTag<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> tagName, PageReference rootPageReference<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        PageDataCollection GetPagesByTag<span style="color: #008000;">&#40;</span>Tag tag, PageReference rootPageReference<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        IEnumerable<span style="color: #008000;">&lt;</span>PageReference<span style="color: #008000;">&gt;</span> GetPageReferencesByTags<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> tagNames<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        IEnumerable<span style="color: #008000;">&lt;</span>PageReference<span style="color: #008000;">&gt;</span> GetPageReferencesByTags<span style="color: #008000;">&#40;</span>IEnumerable<span style="color: #008000;">&lt;</span>Tag<span style="color: #008000;">&gt;</span> tags<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        IEnumerable<span style="color: #008000;">&lt;</span>PageReference<span style="color: #008000;">&gt;</span> GetPageReferencesByTags<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> tagNames, PageReference rootPageReference<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        IEnumerable<span style="color: #008000;">&lt;</span>PageReference<span style="color: #008000;">&gt;</span> GetPageReferencesByTags<span style="color: #008000;">&#40;</span>IEnumerable<span style="color: #008000;">&lt;</span>Tag<span style="color: #008000;">&gt;</span> tags, PageReference rootPageReference<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<p>You&#8217;ll of course find Tags for EPiServer CMS on <a href="http://nuget.episerver.com/">nuget.episerver.com</a>. Go and give it a try &#8211; please let me know how things go and if you have any feedback, leave a comment, <a href="http://twitter.com/frederikvig">tweet me</a> or send me an <a href="mailto:frederikvig@hotmail.com">email</a>.<strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2011/07/tags-for-episerver-cms/" rel="bookmark" title="July 21, 2011">Tags for EPiServer CMS</a></li>
<li><a href="http://www.frederikvig.com/2009/11/removing-duplicates-from-a-pagedatacollection/" rel="bookmark" title="November 27, 2009">Removing duplicates from a PageDataCollection</a></li>
<li><a href="http://www.frederikvig.com/2011/01/creating-custom-templates-in-visual-studio/" rel="bookmark" title="January 30, 2011">Creating custom templates in Visual Studio</a></li>
<li><a href="http://www.frederikvig.com/2009/06/episerver-extension-methods-part-2/" rel="bookmark" title="June 16, 2009">EPiServer Extension Methods part 2</a></li>
<li><a href="http://www.frederikvig.com/2012/02/using-the-asp-net-web-api-framework-with-episerver/" rel="bookmark" title="February 23, 2012">Using the ASP.NET Web API Framework with EPiServer</a></li>
</ul>
<p><!-- Similar Posts took 39.350 ms --></p>
<img src="http://feeds.feedburner.com/~r/frederikvig/~4/fB00TJfTukE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2011/09/tags-version-0-2-released-for-episerver-cms/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.frederikvig.com/2011/09/tags-version-0-2-released-for-episerver-cms/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=tags-version-0-2-released-for-episerver-cms</feedburner:origLink></item>
		<item>
		<title>Easily add comment functionality to EPiServer CMS with DISQUS</title>
		<link>http://feedproxy.google.com/~r/frederikvig/~3/gSEfv8gExKM/</link>
		<comments>http://www.frederikvig.com/2011/08/easily-add-comment-functionality-to-episerver-cms-with-disqus/#comments</comments>
		<pubDate>Sun, 21 Aug 2011 10:41:20 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Disqus]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1618</guid>
		<description><![CDATA[DISQUS is a very popular hosted comment system that makes it very easy to add comment functionality to new or existing sites. It takes care of spam, security (blacklists, whitelists), moderation, mobile and social media support and more. To get started we need to sign up at disqus.com. The next step is adding the necessary ...]]></description>
			<content:encoded><![CDATA[<p>DISQUS is a very popular hosted comment system that makes it very easy to add comment functionality to new or existing sites. It takes care of spam, security (blacklists, whitelists), moderation, mobile and social media support and more. </p>
<p>To get started we need to sign up at <a href="http://disqus.com/admin/register/">disqus.com</a>. The next step is adding the necessary JavaScript code to our site template &#8211; I created a new user control that I then can add to the templates that should have comment functionality enabled.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%</span>@ Control Language<span style="color: #008000;">=</span><span style="color: #666666;">&quot;C#&quot;</span> AutoEventWireup<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> EnableViewState<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> CodeBehind<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Disqus.ascx.cs&quot;</span> Inherits<span style="color: #008000;">=</span><span style="color: #666666;">&quot;EPiServer.Templates.Units.Disqus&quot;</span> <span style="color: #008000;">%&gt;</span>
&nbsp;
<span style="color: #008000;">&lt;</span>div id<span style="color: #008000;">=</span><span style="color: #666666;">&quot;disqus_thread&quot;</span><span style="color: #008000;">&gt;&lt;/</span>div<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>script type<span style="color: #008000;">=</span><span style="color: #666666;">&quot;text/javascript&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008080; font-style: italic;">/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */</span>
    var disqus_shortname <span style="color: #008000;">=</span> <span style="color: #666666;">'example'</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// required: replace example with your forum shortname</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// The following are highly recommended additional parameters. Remove the slashes in front to use.</span>
    var disqus_identifier <span style="color: #008000;">=</span> <span style="color: #666666;">'&lt;%= CurrentPage.PageGuid %&gt;'</span><span style="color: #008000;">;</span>
    var disqus_url <span style="color: #008000;">=</span> <span style="color: #666666;">'&lt;%= CurrentPage.GetExternalUrl() %&gt;'</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/* * * DON'T EDIT BELOW THIS LINE * * */</span>
    <span style="color: #008000;">&#40;</span>function <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        var dsq <span style="color: #008000;">=</span> document<span style="color: #008000;">.</span><span style="color: #0000FF;">createElement</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">'script'</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> dsq<span style="color: #008000;">.</span><span style="color: #0000FF;">type</span> <span style="color: #008000;">=</span> <span style="color: #666666;">'text/javascript'</span><span style="color: #008000;">;</span> dsq<span style="color: #008000;">.</span><span style="color: #0000FF;">async</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
        dsq<span style="color: #008000;">.</span><span style="color: #0000FF;">src</span> <span style="color: #008000;">=</span> <span style="color: #666666;">'http://'</span> <span style="color: #008000;">+</span> disqus_shortname <span style="color: #008000;">+</span> <span style="color: #666666;">'.disqus.com/embed.js'</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#40;</span>document<span style="color: #008000;">.</span><span style="color: #0000FF;">getElementsByTagName</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">'head'</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">||</span> document<span style="color: #008000;">.</span><span style="color: #0000FF;">getElementsByTagName</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">'body'</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">appendChild</span><span style="color: #008000;">&#40;</span>dsq<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&lt;/</span>script<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>noscript<span style="color: #008000;">&gt;</span>Please enable JavaScript to view the <span style="color: #008000;">&lt;</span>a href<span style="color: #008000;">=</span><span style="color: #666666;">&quot;http://disqus.com/?ref_noscript&quot;</span><span style="color: #008000;">&gt;</span>comments powered by Disqus<span style="color: #008000;">.&lt;/</span>a<span style="color: #008000;">&gt;&lt;/</span>noscript<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>a href<span style="color: #008000;">=</span><span style="color: #666666;">&quot;http://disqus.com&quot;</span> <span style="color: #6666cc; font-weight: bold;">class</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;dsq-brlink&quot;</span><span style="color: #008000;">&gt;</span>blog comments powered by <span style="color: #008000;">&lt;</span>span <span style="color: #6666cc; font-weight: bold;">class</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;logo-disqus&quot;</span><span style="color: #008000;">&gt;</span>Disqus<span style="color: #008000;">&lt;/</span>span<span style="color: #008000;">&gt;&lt;/</span>a<span style="color: #008000;">&gt;</span></pre>
</div>
</div>
<p>The disqus_shortname is the shortname you used when you signed up. disqus_identifier is a unique identifier for that page (I used the CurrentPage&#8217;s PageGuid property), and disqus_url is the permalink for the page, I just used the GetExternalUrl() method of the <a href="https://www.coderesort.com/p/epicode/wiki/Extensions">Extensions library for EPiServer CMS</a> for this. That&#8217;s it, now you only need to include the user control in the templates where you want to allow comments.</p>
<p><img src="http://frederikvig.com/wp-content/uploads/disqus.png" alt="" /></p>
<p>Since I tested this locally (not on a public domain) I had to add the following variable to get it to work: var disqus_developer = 1; &#8211; which turns on developer mode for DISQUS.</p>
<h3>Comment count in lists</h3>
<p>If you have a list of pages that have comments you might want to display the number of comments that they have. DISQUS provides us with additional code we can use for just this purpose.</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;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
    var disqus_shortname = 'example'; // required: replace example with your forum shortname
&nbsp;
    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function () {
        var s = document.createElement('script'); s.async = true;
        s.type = 'text/javascript';
        s.src = 'http://' + disqus_shortname + '.disqus.com/count.js';
        (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
    }());
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre>
</div>
</div>
<p>We can add this code to the bottom of our templates (right before the closing body tag). I then created an extension method for building the link to the comments.</p>
<div class="wp_syntax">
<div class="code">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetDisqusCommentLink<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> PageData page<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	var link <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TagBuilder<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;a&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #6666cc; font-weight: bold;">string</span> url <span style="color: #008000;">=</span> page<span style="color: #008000;">.</span><span style="color: #0000FF;">LinkURL</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;#disqus_thread&quot;</span><span style="color: #008000;">;</span>
&nbsp;
	link<span style="color: #008000;">.</span><span style="color: #0000FF;">MergeAttribute</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;href&quot;</span>, url<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	link<span style="color: #008000;">.</span><span style="color: #0000FF;">MergeAttribute</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;data-disqus-identifier&quot;</span>, page<span style="color: #008000;">.</span><span style="color: #0000FF;">PageGuid</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">return</span> link<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span>TagRenderMode<span style="color: #008000;">.</span><span style="color: #0000FF;">Normal</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre>
</div>
</div>
<p>To use the TagBuilder class you&#8217;ll need to add a reference to System.Web.Mvc.dll (version 2 ships with EPiServer CMS 6 R2).</p>
<p><img src="http://frederikvig.com/wp-content/uploads/comment-count.png" alt="" /></p>
<p>There&#8217;s a lot more you can do with DISQUS, I encourage you to take a look at their <a href="http://docs.disqus.com/developers/">developer docs</a> and to try it out.<strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/08/adding-css-and-javascript-files-dynamically-to-your-asp-net-page/" rel="bookmark" title="August 15, 2009">Adding CSS and JavaScript files dynamically to your ASP.NET page</a></li>
<li><a href="http://www.frederikvig.com/2010/10/avoiding-conflicts-when-using-jquery-and-episerver-composer/" rel="bookmark" title="October 25, 2010">Avoiding conflicts when using jQuery and EPiServer Composer</a></li>
<li><a href="http://www.frederikvig.com/2010/05/creating-a-contact-form-with-asp-net-mvc/" rel="bookmark" title="May 13, 2010">Creating a contact form with ASP.NET MVC</a></li>
<li><a href="http://www.frederikvig.com/2009/10/font-resizing-and-printing-with-jquery/" rel="bookmark" title="October 27, 2009">Font resizing and printing with jQuery</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-4-creating-the-standard-page-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 13, 2009">Part 4: Creating the standard page – Create an EPiServer site from scratch</a></li>
</ul>
<p><!-- Similar Posts took 23.021 ms --></p>
<img src="http://feeds.feedburner.com/~r/frederikvig/~4/gSEfv8gExKM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2011/08/easily-add-comment-functionality-to-episerver-cms-with-disqus/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.frederikvig.com/2011/08/easily-add-comment-functionality-to-episerver-cms-with-disqus/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=easily-add-comment-functionality-to-episerver-cms-with-disqus</feedburner:origLink></item>
	</channel>
</rss><!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->

