I was investigating some other issue in R2 and was looking at the output in Fiddler. Much to my surprise, all the requests had caching set to private, and even though resources are cached (they will return a 304 not modified header) it still requires an extra roundtrip just to check.
Here is what Fiddler shows for http://localhost./en:
Using the machine name instead:
Now we’re talking. Still, we can optimize further. As you can see, the files in the Global directory are not cached. In web.config, the Global location is configured like this:
<location path="Global">
<system.web>
<!-- Setup the StaticFileHandler for the wildcard mapping to work in IIS6 -->
<httpHandlers>
<add path="WebResource.axd"
verb="GET"
type="System.Web.Handlers.AssemblyResourceLoader"
validate="true" />
<add path="*"
verb="*"
type="EPiServer.Web.StaticFileHandler, EPiServer"
validate="true" />
</httpHandlers>
</system.web>
<staticFile expirationTime="-1.0:0:0" />
</location>
Expiration is set one day back which of course gives us no caching at all. Change it to:
<staticFile expirationTime="1.0:0:0" />
Which means clients should cache it for a day. This is what Fiddler says:
Note! You might have to do a couple of ctrl+Refresh or empty the cache to make it stick. In my case, it took some time before the /Global files disappeared from Fiddler.
If you want even more caching, turn on the output cache by specifying an expiration in web.config:
<siteSettings
httpCacheExpiration="12:0:0"
httpCacheability="Public"
httpCacheVaryByCustom="path"
httpCacheVaryByParams="id,epslanguage"
As you can see, the start page now expires in 12 hours.
If you’re wondering about that PixelImg thing, it is used by the LogService, and of course should not be cached. If you’re not using the LogService, you should disable it and remove the PixelImg control from your master page.
So, surfing to your local development site using machine name is much more efficient than using localhost. Except when you’re working with your style sheets and JavaScript files, and need them to be checked on each request – then use localhost.
If you’re thinking that this is just a marginal optimization, log in and go to edit mode. This is edit mode from localhost:
Actually, there is more. I’m not showing all the 85 round trips I had to do in order to load it. If you click Edit on the Start Page it leads to another 117 round trips.
And this is edit mode using the machine name:
13 round trips in case you wonder. Editing the start page takes 4 round trips (in contrast to 117).
To repeat, only use localhost when you’re doing development that requires fresh versions of static resources for each round trip. If you’re doing product demos, you’ll have a much more responsive UI if you use the machine name instead, and make sure you “prime” your environment first, meaning you should log in, go to edit mode, and click the Edit tab. This will fill the cache for you.
Per Bjurström has some good posts about caching: