Client Caching in R2 and Localhost

by: Steve Celius

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:
image 

Using the machine name instead:

image

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:

image

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"
 

image

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:

image

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:

image

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:

 

 

11 October 2008


Comments

  1. We have discussed setting a positive expirationTime on VPPs by default (since I would recommend it when going into production). But it may be a bit annoying on demoware and in development where you want to change files often and see the changes instantly. It's not only the client that will cache the file, the kernel cache in IIS will kick in also. Whats your thoughts on this ?
  2. I agree that VPPs should have a positive expiration time. Client caching rules (like the ones from Yahoo http://developer.yahoo.com/performance/rules.html#expires) dictate that the only way you can really be sure the contents of a file is really fresh from the server is rename it. With permanent links in place, this is no problem in EPiServer, and pages that use the file will just work. This is actually a neat feature cache-wise. :-) I don't think is a problem in development, as developers don't put much in VPPs in the first place. For demos, of course this could be a problem, but I don't think it will be a big one. It is easer to train those that do demos than making sure developers turn on VPP expiration. A lot easier actually. :-)
  3. Thanks. You are probably right, I'll start by writing a blog post about the subject.
  4. I have tried what you are suggesting. I get 304 for all my static files even when I use the machinename. Is this OK or do I miss something. So there is allways a roundtrip. Does the webbrowser cache settins have something to do with it? I use IE 7.
Post a comment    
User verification Image for user verification  
Steve Celius

About me

I work for EPiServer in Norway, mostly with technical stuff. Trying to keep up with all the new stuff from the development team. I also hang out on the EPiCode project, why don't you come join us?

You can also follow me on Twitter:

 

Number of visits to this page:
1159

Top five pages on the site:

 

Syndications


Archive


Tag cloud

EPiTrace logger